#include <stdio.h> #include <stdlib.h> #include <time.h> #include <math.h> #include <string.h>
int main() { ??? int n; ??? printf("请输入人数:\n"); ??? scanf("%d",&n); ??? printf("请输入姓名:\n"); ??? char *a[n]; ??? char *temp; ??? for(int i=0;i<n;i++) ??? { ??????? a[i] = (char *)malloc(80); ??????? scanf("%s",a[i]); ??? } ??? for(int i=0;i<n;i++) ??? { ??????? for(int j=i;j<n-1;j++) ??????? { ??????????? if(strcmp(a[j],a[j+1])>0) ??????????????? { ??????????????????? temp = a[j]; ??????????????????? a[j] = a[j+1]; ??????????????????? a[j+1] = temp; ??????????????? } ??????? }
??? } ??? printf("排序结果:\n"); ??? for(int i=0;i<n;i++) ??? { ??????? puts(a[i]); ??????? free(a[i]); ??? }
??? return 0;
}
|