hdu2072(map)

来源:互联网 发布:贵州广电网络股票 编辑:程序博客网 时间:2024/06/06 20:58

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


解题思路:

用map建立一个string 到int的映射,每次遍历字符串,先把空格过滤掉,然后开一个string t 记录单词。每次判断m[ t ]是否已经访问过,如果没有访问过,则标记,计数器+1.


完整代码:

#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <sstream>#include <iomanip>#include <numeric>#include <cstring>#include <climits>#include <cassert>#include <complex>#include <cstdio>#include <string>#include <vector>#include <bitset>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <list>#include <set>#include <map>using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")typedef long long LL;typedef double DB;typedef unsigned uint;typedef unsigned long long uLL;/** Constant List .. **/ //{const int MOD = int(1e9)+7;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f3f3f3f3f3f3fLL;const DB EPS = 1e-9;const DB OO = 1e20;const DB PI = acos(-1.0); //M_PI;string s;map<string , int> m;int main(){    #ifdef DoubleQ    freopen("in.txt","r",stdin);    #endif    while(getline(cin , s))    {        if(s == "#")            break;        int len = s.length();        m.clear();        int cnt = 0;        for(int i = 0 ; i < len ; i ++)        {            if(s[i] == ' ')                continue;            string t = "";            for( ; i < len ; i ++)            {                if(s[i] != ' ')                    t += s[i];                else                    break;            }            if(m[t] == 0)            {                m[t] = 1;                cnt ++;            }        }        cout << cnt << endl;    }}


0 0