hdu 1251 统计难题

来源:互联网 发布:完美root软件 编辑:程序博客网 时间:2024/06/08 03:48

题目:http://acm.hdu.edu.cn/showproblem.php?pid=1251

分析:字典树模板题,也可以用STL中的map(映射)。。。

代码:

///STL map#include<iostream>#include<map>#include<cstdio>#include<cstring>using namespace std;map<string,int> mp;int main(){    char str[12];    while(gets(str)){        int len=strlen(str);        if(!len) break;        for(int i=len;i>=0;i--){            str[i]='\0';            mp[str]++;        }    }    while(gets(str))        cout<<mp[str]<<endl;}