当前位置:网站首页>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
边栏推荐
- C language pointer interview question - the second bullet
- Rules for using init in golang
- Summary of the most comprehensive CTF web question ideas (updating)
- 7-17 crawling worms (15 points)
- C # use smtpclient The sendasync method fails to send mail, and always returns canceled
- MySQL transaction mvcc principle
- 2022-2028 global seeder industry research and trend analysis report
- Normal vector point cloud rotation
- Write a jison parser from scratch (6/10): parse, not define syntax
- Hands on deep learning (45) -- bundle search
猜你喜欢

Four common methods of copying object attributes (summarize the highest efficiency)

2022-2028 global intelligent interactive tablet industry research and trend analysis report

el-table单选并隐藏全选框

Advanced technology management - how to design and follow up the performance of students at different levels

Leetcode (Sword finger offer) - 35 Replication of complex linked list

Hands on deep learning (42) -- bi-directional recurrent neural network (BI RNN)
Web端自动化测试失败原因汇总

2022-2028 global industry research and trend analysis report on anterior segment and fundus OTC detectors

Kubernetes CNI 插件之Fabric

Svg image quoted from CodeChina
随机推荐
Global and Chinese markets for laser assisted liposuction (LAL) devices 2022-2028: Research Report on technology, participants, trends, market size and share
lolcat
C # use gdi+ to add text to the picture and make the text adaptive to the rectangular area
Hands on deep learning (37) -- cyclic neural network
2022-2028 global edible probiotic raw material industry research and trend analysis report
MATLAB小技巧(25)竞争神经网络与SOM神经网络
Hands on deep learning (35) -- text preprocessing (NLP)
Write a mobile date selector component by yourself
Hands on deep learning (36) -- language model and data set
Latex download installation record
Golang 类型比较
PHP personal album management system source code, realizes album classification and album grouping, as well as album image management. The database adopts Mysql to realize the login and registration f
The child container margin top acts on the parent container
How to display √ 2 on the command line terminal ̅? This is actually a blog's Unicode test article
Hands on deep learning (43) -- machine translation and its data construction
Sort out the power node, Mr. Wang he's SSM integration steps
2022-2028 global probiotics industry research and trend analysis report
浅谈Multus CNI
Global and Chinese market of planar waveguide optical splitter 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese market of air fryer 2022-2028: Research Report on technology, participants, trends, market size and share