Uva--10420 (字符串,检索)
2014-06-03 00:00:35
题意&思路:简单题。
#include <cstdio> #include <cstring> #include <algorithm> #include <iostream> using namespace std; struct Country{ char name[80]; }; Country cou[2005]; bool cmp(Country a,Country b){ return strcmp(a.name,b.name) < 0; } int main(){ int n; char t; scanf("%d",&n); for(int i = 0 ; i < n; ++i){ scanf("%s",cou[i].name); t = getchar(); while(t != '\n'){ t = getchar(); } } sort(cou,cou + n,cmp); int cnt = 1; for(int i = 0; i < n; ++i){ if(strcmp(cou[i].name,cou[i + 1].name) != 0 || i == n - 1){ cout << cou[i].name << " " << cnt << endl; cnt = 1; } else{ ++cnt; } } return 0; }