HDU 1113(map的使用)
题意:给一串字符串字典,再给一串字符串,求字典中是否存在与字符串字符相同的字符串。
#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;
}
}
还没有评论,来说两句吧...