HDU 1113(map的使用)

来源:互联网 发布:php服务器怎么绑定域名 编辑:程序博客网 时间:2024/05/29 16:28

题意:给一串字符串字典,再给一串字符串,求字典中是否存在与字符串字符相同的字符串。

#include <iostream>#include <string>#include <map>#include <algorithm>using namespace std;void main(){    map<string, string> dictionary;    string s, t;    while (cin >> s && s != "XXXXXX")    {        t = s;        sort(s.begin(), s.end());        dictionary[t] = s;    }    while (cin >> s && s != "XXXXXX")    {        int flag = 0;        t = s;        sort(s.begin(), s.end());        map<string, string>::iterator it;        for (it = dictionary.begin(); it != dictionary.end(); ++it)        {            if (it->second == s)            {                cout << it->first << endl;                flag = 1;            }        }        if (!flag)        {            cout << "NOT A VALID WORD" << endl;        }        cout << "******" << endl;    }}


 

0 0
原创粉丝点击