我拿到UVa上就AC
到了這邊就RE
以下是code :
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
const int MAXLINE = 2000;
const int MAXCHAR = 75;
char girl[MAXLINE][MAXCHAR+1];
char nati[MAXLINE][MAXCHAR+1];
int cmp_string(const void* _a, const void* _b) {
char* a = (char*)_a;
char* b = (char*)_b;
return strcmp(a, b);
}
int main() {
int n;
while(scanf("%d", &n) == 1) {
getchar();
memset(girl, 0, sizeof(girl));
memset(nati, 0, sizeof(nati));
int i, j;
for(i = 0; i < n; i++) {
fgets(girl[i], MAXCHAR+1, stdin);
for(j = 0; girl[i][j] != 32; j++)
nati[i][j] = girl[i][j];
nati[i][j] = '\0';
}
qsort(nati, n, sizeof(nati[0]), cmp_string);
char tmp[MAXCHAR+1];
int count = 0;
strcpy(tmp, nati[0]);
for(i = 0; i < n; i++)
if(strcmp(tmp, nati[i])) {
printf("%s %d\n", tmp, count);
strcpy(tmp, nati[i]);
count = 1;
}
else
count++;
printf("%s %d\n", tmp, count);
}
return 0;
}
寫得很亂...多包涵