#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
//定义字符串
char shuzu[6][100]={0};
//遇到空格或回车系统会认为一个字符串输入结束了
printf("请输入六个字符串以空格或者回车隔开\n");
//输入字符串
for (int i =0; i<6; i++) {
scanf("%s",shuzu[i]);
}
//用冒泡法排序
//strcmp是字符串比较函数
//strcpy是字符串拷贝函数
for (int i =0; i<6-1; i++) {
for (int j = 0; j<6-i-1; j++) {
if (strcmp(shuzu[j],shuzu[j+1])>0) {
char temp[100] = {0};
strcpy(temp,shuzu[j]);
strcpy(shuzu[j],shuzu[j+1]);
strcpy(shuzu[j+1],temp);
}
}
}
//输出排序结果
for (int i =0; i<6; i++) {
printf("%s ",shuzu[i]);
}
return 0;
}
|
|