hdu-1251(string+map)

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

思路:重点是用gets输入,而且用a[20],不能直接输入string类型的。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
using namespace std;
string str,s;
char a[20];
map <string,int> mp;
int main(void)
{
    char c;
    int i,j,pt=0,ans,k;
    while(gets(a),a[0]!='\0')
    {
        str=a;
        s="";
        for(i=0;i<str.length();i++)
        {
            s+=str[i];
            mp[s]++;
        }
        //getchar();
    }
    while(cin>>str)
    {
        cout<<mp[str]<<endl; 
    }
    return 0;
}

 

posted @ 2018-10-23 20:29  麟阁  阅读(109)  评论(0编辑  收藏  举报