当前位置:网站首页>Wrong question (character array)
Wrong question (character array)
2022-06-11 02:00:00 【Jihai】
1. Insert string
Title Description : Enter two strings a and b, take b The largest character in the string is inserted into a After the smallest character in the string .
The sample input : MynameisAmy
MynameisJane
Sample output : MynameisAymy
Tips : The string length does not exceed 100
#include <stdio.h>
#include <string.h>
int main()
{
/*********Begin*********/
char a[100],b[100];
int i,j,m,n,max,min;
gets(a);
gets(b);
m=strlen(a);
n=strlen(b);
a[min]=a[0];
for(i=0;i<m;i++){
if(a[min]>=a[i]) min=i;
}
for(i=0;i<=min;i++){
printf("%c",a[i]);
}
b[max]=b[0];
for(i=0;i<n;i++){
if(b[max]<=b[i]) max=i;
}
printf("%c",b[max]);
for(i=min+1;i<m;i++){
printf("%c",a[i]);
}
/*********End**********/
return 0;
}2. Character statistics
For a given string , Count the number of times the number of characters appear .
Input There are multiple lines of input data , The first line is an integer n, Indicates the number of test instances , Follow behind n That's ok , Each line contains a string of letters and numbers .
Output For each test case , Output the number of values in the string , One line per output .
The sample input : 2asdfasdf123123asdfasdf
asdf111111111asdfasdfasdf
Sample output : 6
9
#include<stdio.h>
int main(void)
{
/*********Begin*********/
int n,i,j,count;
char s[10][50];
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%s",&s[i]);
}
for(i=0;i<n;i++)
{
count=0;
for(j=0;s[i][j]!='\0';j++)
if(s[i][j]>='0'&&s[i][j]<='9')
count++;
printf("%d\n",count);
}
/*********End**********/
return 0;
}3. Input multidimensional character array by line with pointer
Title Description : Input 3 That's ok , Each row n A string , Output in order of small to large
The sample input : cde
afg
abc
Sample output : abc
afg
cde
#include<stdio.h>
#include<string.h>
int main(void)
{
/*********Begin*********/
char str[3][100];
int i,j,k;
for(k=0;k<3;k++)
gets(str[k]);
char *ps[3]={str[0], str[1],str[2]};
char *temp;
for(i=0;i<3;i++)
{
for(j=i+1;j<3;j++)
{
if(strcmp(ps[i],ps[j])>0)
{
temp=ps[i];
ps[i]=ps[j];
ps[j]=temp;
}
}
}
for(i=0;i<3;i++)
printf("%s\n",ps[i]);
/*********End**********/
return 0;
}边栏推荐
- Dialog AlertDialog 、SimpleDialog、showModalBottomSheet、showToast Flutter 自定义 Dialog
- 1.3 introduction to ROS UAV
- Leetcode 1567 maximum length of subarray with positive product
- 2021-07-18 ROS笔记-基础和通讯
- flutter_ Swiper carousel map plug-in
- Loki 学习总结(1)—— Loki 中小项目日志系统的不二之选
- 關於概率統計中的排列組合
- 【HaaS Hands-On】全新视频节目上线 创意案例我们一起上手做 第一期E01: 物联网工程师 和你一起上手做遥控机械臂
- 神经网络极简史,神经网络知识点整理
- 2021-7-18 ROS notes XML language related
猜你喜欢

面试官:介绍一下你简历中的项目,细讲一点,附项目实战

【交通标志识别】基于matlab GUI YCbCr特征提取+BP神经网络交通标志识别【含Matlab源码 1869期】

---Arrange numbers---

In May, the main growth ranking list (platform of station B) of the single flying melon data up was released

爱思唯尔---Elseviewer---预印本在线发表通知

Method of using dism command to backup driver in win11 system

Project sorting of Online Exercise System Based on gin and Gorm

AI fanaticism | come to this conference and work together on the new tools of AI!

How to reinstall win11 drawing tool when it is missing

2021-2-14 gephi learning notes
随机推荐
Within one month, the broadcasting volume has increased by 9million, and station B has three traffic growth passwords!
【MATLAB】MATLAB图像处理基本操作
并发编程基础底层原理学习(四)
[cloud native | kubernetes] actual combat of ingress case
[leetcode] merge K ascending linked lists
2021-02-03美赛前MATLAB的学习笔记(灰色预测、线性规划)
China-open-ssl编译的一些记录
【MATLAB】图像分割
2021-7-18 ROS notes XML language related
2021-02-27image processing of MATLAB
【MATLAB】图像复原
1.6 Px4 initialization calibration
神经网络极简史,神经网络知识点整理
1.5 Px4 vehicle selection
---Arrange numbers---
【云原生 | Kubernetes篇】Ingress案例实战
晚餐阿帮的手艺
[leetcode] delete duplicate Element II in the sorting linked list
2021-2-26 compilation of programming language knowledge points
2021-02-03 learning notes of MATLAB before the US games (grey prediction and linear programming)