题目描述:https://pycoder.blog.csdn.net/article/details/124600540
#include
#include
#include
#include
int myCmp(const void *a, const void *b)
{
char *aa = (char *)a;
char *bb = (char *)b;
return aa[strlen(aa) - 1] - bb[strlen(bb) - 1];
}
int main(void)
{
char str[10000] = {0};
int arr_inx = 0;
char arr[1000][10] = {0};
scanf("%s", str);
char *tmp;
tmp = strtok(str, ",");
strcpy(arr[arr_inx++], tmp);
while (1) {
tmp = strtok(NULL, ",");
if (tmp == NULL) break;
strcpy(arr[arr_inx++], tmp);
}
qsort(arr, arr_inx, sizeof(arr[0]), myCmp);
for (int i = 0; i < arr_inx - 1; i++) {
printf("%s,", arr[i]);
}
printf("%s\n", arr[arr_inx - 1]);
return 0;
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)