当前位置:网站首页>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 whitesample output :
After sorted:
black
blue
red
white
yellowThe 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
边栏推荐
- Fatal error in golang: concurrent map writes
- AMLOGIC gsensor debugging
- 165 webmaster online toolbox website source code / hare online tool system v2.2.7 Chinese version
- In the case of easyUI DataGrid paging, click the small triangle icon in the header to reorder all the data in the database
- H5 audio tag custom style modification and adding playback control events
- 2022-2028 global small batch batch batch furnace industry research and trend analysis report
- xxl-job惊艳的设计,怎能叫人不爱
- C language pointer classic interview question - the first bullet
- Normal vector point cloud rotation
- Write a jison parser from scratch (4/10): detailed explanation of the syntax format of the jison parser generator
猜你喜欢

2022-2028 global seeder industry research and trend analysis report

Hands on deep learning (32) -- fully connected convolutional neural network FCN

Machine learning -- neural network (IV): BP neural network

How can people not love the amazing design of XXL job

Daughter love: frequency spectrum analysis of a piece of music

Hands on deep learning (34) -- sequence model

2022-2028 global elastic strain sensor industry research and trend analysis report

Fabric of kubernetes CNI plug-in

Daughter love in lunch box

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
随机推荐
Baidu R & D suffered Waterloo on three sides: I was stunned by the interviewer's set of combination punches on the spot
MATLAB小技巧(25)竞争神经网络与SOM神经网络
Global and Chinese PCB function test scale analysis and development prospect planning report Ⓑ 2022 ~ 2027
Daughter love: frequency spectrum analysis of a piece of music
SQL replying to comments
How to batch change file extensions in win10
Golang defer
Hands on deep learning (44) -- seq2seq principle and Implementation
Modules golang
el-table单选并隐藏全选框
What are the advantages of automation?
Summary of small program performance optimization practice
How can people not love the amazing design of XXL job
Global and Chinese markets of thrombography hemostasis analyzer (TEG) 2022-2028: Research Report on technology, participants, trends, market size and share
智能网关助力提高工业数据采集和利用
Svg image quoted from CodeChina
Global and Chinese market of sampler 2022-2028: Research Report on technology, participants, trends, market size and share
Hands on deep learning (43) -- machine translation and its data construction
`Example of mask ` tool use
Fatal error in golang: concurrent map writes