UVA 10420-List of Conquests
题目大意:给出几组国家加人名,求出每个国家人数
解题思路:获取国家名,然后排序求解
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
int cmp(const void *a, const void *b) {
return strcmp((char*)a, (char*)b);
}
int main() {
int n;
cin >> n;
char a[10000][10000];
char b[10000][10000];
int c[10000] = {0};
char d[10000][10000];
getchar();
for(int i = 0; i < n; i++) {
gets(a[i]);
}
memset(b, '\0', sizeof(b));
for(int i = 0; i < n; i++) {
for(int j = 0; a[i][j] != ' '; j++) {
b[i][j] = a[i][j];
}
}
qsort(b, n, sizeof(b[0]), cmp);
strcpy(d[0], b[0]);
c[0]++;
int s = 0;
for(int j = 1; j < n; j++) {
if(strcmp(b[j], d[s]) != 0) {
s++;
strcpy(d[s], b[j]);
}
c[s]++;
}
for(int j = 0; j <= s; j++) {
printf("%s %d\n",d[j], c[j]);
}
return 0;
}