#include <stdio.h> int main(){ char matric[5][80]; char c; char new_matric[5][80]; int num_arr[5]; int new_num_arr[5]; for (int i=0;i<5;i++){ // 获取到所有的字符串 int count=0; while (scanf("%c",&c)!=EOF && c!=' ' && c!='\t' && c!='\n'){ matric[i][count]=c; count++; } num_arr[i]=count; } // 尝试打印字符串 for (int i=0;i<5;i++){ int count=0; for (int j=0;j<5;j++){ //打印具体的字符串 // for (int l=0;l<num_arr[i];l++){ // printf("%c",matric[i][l]); // } // printf(" "); // for (int l=0;l<num_arr[j];l++){ // printf("%c",matric[j][l]); // } // printf("\n"); if (i!=j){ int l=0; while (l<80){ if (l<num_arr[i]){ if (matric[i][l]>matric[j][l]){count++;break;} if (matric[i][l]<matric[j][l]){break;} } l++; } } } // printf("i=%d count=%d\n",i,count); for (int l=0;l<num_arr[i];l++){ new_matric[count][l]=matric[i][l]; } new_num_arr[count]=num_arr[i]; } // //打印 printf("After sorted:\n"); for (int i=0;i<5;i++){ for (int l=0;l<new_num_arr[i];l++){ printf("%c",new_matric[i][l]); } printf("\n"); } return 0; }
c语言编程练习题:7-143 字符串排序
作者:yunjinqi
类别:编程
日期:2023-05-31 17:24:44
阅读:602 次
消耗积分:0 分
版权所有,转载本站文章请注明出处:云子量化, https://www.yunjinqi.top/article/268
最新文章
系统当前共有 404 篇文章