当前位置:网站首页>String sort
String sort
2022-07-03 14:15:00 【Study hard 867】
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
Code :
#include <stdio.h>
#include <string.h>
int main(){
char a[5][80];
char b[1][80];
int i,j;
for(i=0;i<5;i++){
scanf("%s",a[i]);
}
for(i=0;i<5;i++){
strcpy(b[0],a[i]);
for(j=i+1;j<5;j++){
if(strcmp(b[0],a[j])>0){
strcpy(b[0],a[j]);
strcpy(a[j],a[i]);
strcpy(a[i],b[0]);
}
}
}
printf("After sorted:\n");
for(i=0;i<4;i++){
printf("%s\n",a[i]);
}
printf("%s",a[4]);
}
边栏推荐
- Leetcode (4) - - trouver la médiane de deux tableaux ordonnés positifs
- jvm-对象生命周期
- JS input number and standard digit number are compared. The problem of adding 0 to 0
- 玖逸云黑免费无加密版本源码
- Common plug-ins for vite project development
- js 2023. String pair equal to the target string after connection
- 虽然不一定最优秀,但一定是最努力的!
- JVM garbage collector
- JS get DPI, PX to cm, cm to PX
- [acnoi2022] guess numbers
猜你喜欢
Interface for querying IP home
Concat and concat_ Ws() differences and groups_ Use of concat() and repeat() functions
Example analysis of QT learning 18 login dialog box
7-15 calculation of PI
[email protected] Nanoparticles) | nano metal organic framework carry"/>
Metal organic framework material zif-8 containing curcumin( [email protected] Nanoparticles) | nano metal organic framework carry
必贝特医药冲刺科创板:年营收97万亏损1.37亿 拟募资20亿
JVM class loading
7-7 12-24 hour system
Leetcode (4) -- find the median of two positively ordered arrays
玖逸云黑免费无加密版本源码
随机推荐
Common plug-ins for vite project development
一文了解微分段应用场景与实现机制
Facebook 如何将 Instagram 从 AWS 搬到自己的服务器
concat和concat_ws()区别及group_concat()和repeat()函数的使用
Invalid Z-index problem
QT learning 21 standard dialog box in QT (Part 2)
Exercise 6-1 classify and count the number of characters
Exercise 10-3 recursive implementation of exponential functions
js 2023. String pair equal to the target string after connection
剑指 Offer 28. 对称的二叉树
Understanding of closures
全局事件总线
Exercise 8-2 calculate the sum and difference of two numbers
Vite project commissioning
Exercise 8-8 moving letters
QT learning 25 layout manager (4)
Cross linked cyclodextrin metal organic framework loaded methotrexate slow-release particles | metal organic porous material uio-66 loaded with flavonoid glycosides | Qiyue
Fabric. JS document
protobuf与grpc
JVM垃圾回收机