当前位置:网站首页>Exercise 8-7 string sorting (20 points)
Exercise 8-7 string sorting (20 points)
2022-07-04 09:47:00 【skeet follower】
This question requires the preparation of procedures , Read in 5 A string , Output in order of small to large .
Input format :
Input is space delimited 5 Non empty strings , Each string does not contain spaces 、 tabs 、 Blank characters such as line breaks , The length is less than 80.
Output format :
Output the sorted results in the following format :
After sorted:
One string per line
sample input :
red yellow blue black white
sample output :
After sorted:
black
blue
red
white
yellow
The code is as follows :
#include<stdio.h>
int main()
{
char a[5][80]={'0'};
char temp[80]={'0'};
int i,j;
for(i=0;i<5;i++){
scanf("%s",&a[i]);
}
for(i=0;i<4;i++){// Bubble sort
for(j=0;j<4-i;j++){
if(strcmp(a[j],a[j+1])>0){//strcmp() Function comparison size usage
strcpy(temp,a[j]);//strcpy() Usage of copy string
strcpy(a[j],a[j+1]);
strcpy(a[j+1],temp);
}
}
}
printf("After sorted:\n"); // Print the sorted string
for(i=0;i<5;i++){
printf("%s\n",a[i]);
}
return 0;
}
summary : The difficulty of this question is to check whether it is right strcpy() and strcmp() function , And the skilled application of bubble sorting ;strcpy() and strcmp() If you forget, you can refer to this blog to help recall :C Language implementation strcpy and strcmp_qq_42820622 The blog of -CSDN Blog _c Language strcmp
边栏推荐
- 2022-2028 global gasket metal plate heat exchanger industry research and trend analysis report
- mmclassification 标注文件生成
- Hands on deep learning (46) -- attention mechanism
- 什么是 DevSecOps?2022 年的定义、流程、框架和最佳实践
- Daughter love in lunch box
- On Multus CNI
- Global and Chinese market of wheel hubs 2022-2028: Research Report on technology, participants, trends, market size and share
- 2022-2028 global intelligent interactive tablet industry research and trend analysis report
- Global and Chinese trisodium bicarbonate operation mode and future development forecast report Ⓢ 2022 ~ 2027
- Golang type comparison
猜你喜欢
Svg image quoted from CodeChina
Matlab tips (25) competitive neural network and SOM neural network
Log cannot be recorded after log4net is deployed to the server
Machine learning -- neural network (IV): BP neural network
2022-2028 global gasket metal plate heat exchanger industry research and trend analysis report
MySQL develops small mall management system
C language pointer interview question - the second bullet
2022-2028 global intelligent interactive tablet industry research and trend analysis report
2022-2028 global optical transparency industry research and trend analysis report
libmysqlclient. so. 20: cannot open shared object file: No such file or directory
随机推荐
2022-2028 global gasket metal plate heat exchanger industry research and trend analysis report
Global and Chinese market of sampler 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese market of wheel hubs 2022-2028: Research Report on technology, participants, trends, market size and share
Matlab tips (25) competitive neural network and SOM neural network
2022-2028 global protein confectionery industry research and trend analysis report
Hands on deep learning (43) -- machine translation and its data construction
华为联机对战如何提升玩家匹配成功几率
Exercise 9-5 address book sorting (20 points)
Global and Chinese markets for laser assisted liposuction (LAL) devices 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese markets of water heaters in Saudi Arabia 2022-2028: Research Report on technology, participants, trends, market size and share
2022-2028 global tensile strain sensor industry research and trend analysis report
2022-2028 global optical transparency industry research and trend analysis report
2022-2028 global industry research and trend analysis report on anterior segment and fundus OTC detectors
JDBC and MySQL database
QTreeView+自定义Model实现示例
Go context basic introduction
MySQL transaction mvcc principle
2022-2028 global edible probiotic raw material industry research and trend analysis report
System.currentTimeMillis() 和 System.nanoTime() 哪个更快?别用错了!
Hands on deep learning (44) -- seq2seq principle and Implementation