当前位置:网站首页>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
边栏推荐
- 品牌连锁店5G/4G无线组网方案
- Hands on deep learning (41) -- Deep recurrent neural network (deep RNN)
- Daughter love in lunch box
- Investment analysis and prospect prediction report of global and Chinese high purity tin oxide Market Ⓞ 2022 ~ 2027
- Deadlock in channel
- 2022-2028 global probiotics industry research and trend analysis report
- Summary of the most comprehensive CTF web question ideas (updating)
- mmclassification 标注文件生成
- Explanation of for loop in golang
- 智慧路灯杆水库区安全监测应用
猜你喜欢
Hands on deep learning (37) -- cyclic neural network
mmclassification 标注文件生成
C language pointer interview question - the second bullet
Normal vector point cloud rotation
2022-2028 global gasket plate heat exchanger industry research and trend analysis report
智慧路灯杆水库区安全监测应用
JDBC and MySQL database
SSM online examination system source code, database using mysql, online examination system, fully functional, randomly generated question bank, supporting a variety of question types, students, teache
直方图均衡化
Hands on deep learning (35) -- text preprocessing (NLP)
随机推荐
MySQL foundation 02 - installing MySQL in non docker version
Trees and graphs (traversal)
自动化的优点有哪些?
Four common methods of copying object attributes (summarize the highest efficiency)
Daughter love: frequency spectrum analysis of a piece of music
智能网关助力提高工业数据采集和利用
PHP student achievement management system, the database uses mysql, including source code and database SQL files, with the login management function of students and teachers
Golang 类型比较
C language pointer interview question - the second bullet
什么是 DevSecOps?2022 年的定义、流程、框架和最佳实践
Machine learning -- neural network (IV): BP neural network
Report on investment analysis and prospect trend prediction of China's MOCVD industry Ⓤ 2022 ~ 2028
Modules golang
The child container margin top acts on the parent container
Explanation of for loop in golang
SQL replying to comments
回复评论的sql
2022-2028 global edible probiotic raw material industry research and trend analysis report
Hands on deep learning (36) -- language model and data set
Mmclassification annotation file generation