第五周编程总结

本题要求编写程序,输入若干英文单词,对这些单词按长度从小到大排序后输出。如果长度相同,按照输入的顺序不变。 输入格式: 输入为若干英文单词,每行一个,以#作为输入结束标志。其中英文单词总数不超过20个,英文单词为长度小于10的仅由小写英文字母组成的字符串。 输出格式: 输出为排序后的结果,每个单词后面都额外输出一个空格。 输入样例: blue red yellow green purple # 输出样例: red blue green yellow purple 作者: 张泳 单位: 浙江大学城市学院 时间限制: 400 ms 内存限制: 64 MB 代码长度限制: 16 KB

编译器 (33)

4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

{
char str[20][10],t[20],str1[10];
int i,j,n=0; while(1) {
scanf("%s",str1);
if(str1[0]=='#')
{
break;
}
else
{
strcpy(str[n],str1);
n++;
}
}
for(i=0;i<n-1;i++) for(j="0;j<n-i-1;j++)" {="" if(strlen(str[j])="">strlen(str[j+1]))
{
strcpy(t,str[j]);
strcpy(str[j],str[j+1]);
strcpy(str[j+1],t);
}
}
for(i=0;i<n;i++)
{
printf("%s ",str[i]);
}

原文地址:https://www.cnblogs.com/Bowen----/p/10623812.html