hdu 1251 统计难题 (map水过)

# include <stdio.h>
# include <algorithm>
# include <string>
# include <map>
# include <iostream>
using namespace std;
int main()
{
    char a;
    string  x;
    map<string,int>q;
    while(true)
    {
        scanf("%c",&a);
        if(a=='\n')
        {
            scanf("%c",&a);
            x="";//一个结束x初始化
        }
        if(a=='\n')//连续两个\n结束了母串的输入
            break;
        x+=a;
        q[x]+=1;
    }
    while(cin>>x)
        printf("%d\n",q[x]);
    return 0;
}

posted @ 2015-12-31 17:37  lcchuguo  阅读(114)  评论(0编辑  收藏  举报