UVa 10420 List of Conquests

/* coder: ACboy date: 2010-2-25 result: 1AC description: UVa 10420 List of Conquests */ #include <iostream> #include <sstream> #include <algorithm> #include <string> using namespace std; struct Node { string country; string womenName; }; Node node[2010]; int cmp(Node a, Node b) { if (a.country == b.country) { return a.womenName < b.womenName; } else { return a.country < b.country; } } int main() { int i, j; int n; #ifndef ONLINE_JUDGE freopen("10420.txt", "r", stdin); #endif string input; cin >> n; getline(cin, input); for (i = 0; i < n; ++i) { getline(cin, input); istringstream in(input); in >> node[i].country; while (!in.eof()) { string temp; in >> temp; node[i].womenName += temp; } } sort(node, node + n, cmp); string k = node[0].country; string name = node[0].womenName; int count = 1; for (j = 1; j < n; j++) { if (k == node[j].country) { count++; } else { cout << k << " " << count << endl; k = node[j].country; name = node[j].womenName; count = 1; } } cout << k << " " << count << endl; return 0; }

你可能感兴趣的:(UVa 10420 List of Conquests)