Sicily 1825 Nickname

来源:互联网 发布:郎咸平 离婚 知乎 编辑:程序博客网 时间:2024/04/30 13:13

巧妙利用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;}


原创粉丝点击