回复 10楼 beyondyf
http://acm.zjgsu.不过这是我们测试的题目,你不一定可以做
#include <stdio.h> #include <string.h> #include <stdlib.h> int cmp(const void *a, const void *b) { return strcmp(*(char **)a, *(char **)b); } int main() { char str[1005][32]; char *list[1005]; int n, i, len, sum, j; char temp; while(scanf("%d", &n), n) { sum = 0; for(i = 0; i < n; i++) scanf("%s", str[i]); for(i = 0; i < n; i++) { len = strlen(str[i])-4; if(len>0 && !strcmp(str[i]+len,".exe")) { temp = str[i][len]; str[i][len] = 0; for(j = 0;j<n;j++) { if(j == i)continue; if(!strcmp(str[i],str[j])) { list[sum++] = str[j]; break; } } str[i][len] = temp; } } qsort(list, sum, sizeof(char *), cmp); for(i = 0; i < sum; i++) printf("%s.exe\n", list[i]); } return 0; }
#include<stdio.h> #include<string.h> int cmp(const void *a, const void *b) { return strcmp(*(char **)a, *(char **)b); } int main() { char a[2000][24], *p[2000]; int an, n, i, len; while(scanf("%d", &n), n) { for(an = i = 0; i < n; i++, an++) { scanf("%s", a[an]); len = strlen(a[an]) - 4; p[an] = a[an]; if(len >= 0 && !strcmp(a[an] + len, ".exe")) { strcpy(a[an + 1], a[an]); a[an++][len] = '\0'; p[an] = a[an]; } } qsort(p, an, sizeof(char *), cmp); for(i = 1; i < an; i++) if(!strcmp(p[i], p[i - 1])) printf("%s.exe\n", p[i]); } return 0; }