#include<stdio.h> #include<string.h> #include<math.h> #include<malloc.h> int main(){ int n; while (scanf("%d", &n), n != 0) { char **p = (char **)malloc(n * sizeof(char *)); for (int i = 0;i < n;i++) { p[i] = (char *)malloc(20 * sizeof(char)); } char *q = (char *)malloc(n * sizeof(char)); int count = 0; for (int i = 0;i < n;i++) { scanf("%s",q); int len = strlen(q); if (len >= 5) { if (q[len - 1] == 'e'&&q[len - 2] == 'x'&&q[len - 3] == 'e'&&q[len - 4] == '.') { int flag = 1; for (int i = 0;i < count + 1;i++) { if (strcmp(q, p[i]) == 0) flag = 0; } if (flag) { strcpy(p[count], q); count++; } } } } for (int i = count - 1;i > 0;i--) { int flag = 1; for (int j = 0;j < i;j++) { if (strcmp(p[j], p[j + 1])>0) { char *temp = (char *)malloc(20 * sizeof(char)); strcpy(temp, p[j]); strcpy(p[j], p[j+1]); strcpy(p[j+1], temp); flag = 0; } } if (flag == 1) break; } for (int i = 0;i < count;i++) { printf("%s\n", p[i]); } } } |
Double click to view unformatted code.