【杭电100题】【map】2072 单词数

原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2072
本题方法大全:https://blog.csdn.net/piaocoder/article/details/41902793
啊啊啊今天第二道自己AC的题,虽然在空格上卡了很久,不过还是利用自己之前学到的map的知识解决了qwq…
虽然代码有点丑陋,但是纪念意义更重,所以还是放上来qwq
充分说明了,人生不要放弃,总会遇见第二道水题

#include <iostream>
#include <map>
#include <string>
#include <cctype>

using namespace std;

map <string, int> m1;

int main()
{
    int num=0;
    string s="";
    char c;
    while((c=getchar())&&(c!='#'))
    {
        if(c==' '||c=='\n')
        {
            if(s.length()&&m1.count(s)==0)
            {
                num++;
                m1[s]=1;
            }
            s="";
        }
        else
        {
            s+=c;
        }

        if(c=='\n')
        {
            cout<<num<<endl;
            num=0;
            m1.erase( m1.begin(), m1.end() );
        }
    }
    return 0;
}


猜你喜欢

转载自blog.csdn.net/qq_41727666/article/details/88322900