巧妙利用STL就可以了
#include <map>
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
struct node
{
string name;
int times;
void add()
{
times++;
}
node(string n)
{
name = n;
times = 1;
}
};
int main()
{
int n,t,i;
string temp;
int need =0;
int s1, s2;
map<string, node>::iterator p;
map<string, node> map1;
cin >> t;
while ( t-- ) {
cin >> n;
while(n--)
{
cin >> temp;
for ( i=0;i<temp.length();i++ )
temp[i]=tolower(temp[i]);
s1 = map1.size();
map1.insert(pair<string, node>(temp, node(temp)));
s2 = map1.size();
if (s1 == s2)
{
p = map1.find(temp);
p->second.add();
}
}
for (p = map1.begin(); p != map1.end(); p++)
{
cout << p->first << " " << p->second.times << endl;
}
cout << endl;
map1.clear();
}
//system( "pause" );
return 0;
}