UVA 10420 - List of Conquests
字符串排序。
[cpp]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int cmp(const void *a, const void *b) {
char *_a = (char *)a;
char *_b = (char *)b;
return strcmp(_a, _b);
}
int main() {
char str[2005][80];
int n;
scanf("%d", &n);
for (int i=0; i<n; i++) {
scanf("%s", str[i]);
gets(str[i+1]); // 把女人姓名忽略掉
}
qsort(str, n, sizeof (str[0]), cmp);
int tmp = 1;
for (int i=1; i<=n; i++) {
if (0==strcmp(str[i], str[i-1]) && i<n) {
tmp++;
}
else {
printf("%s %d\n", str[i-1], tmp);
tmp = 1;
}
}
return 0;
}
补充:软件开发 , C++ ,