题目链接
题意:我们先给出一系列基础字符串,之后用“XXXXXX”隔开,我们将列写查询字符串,假如查询字符串换一种排列可以得出上面的字符串,那么,我们就输出上面的字符串,不然输出:“ NOT A VALID WORD ”。
这就是一道关于STL中map的应用题。
完整代码:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <limits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define lowbit(x) ( x&(-x) )
#define pi 3.141592653589793
#define e 2.718281828459045
using namespace std;
typedef long long ll;
const int maxN=100005;
string a, b;
map<string, string> st;
map<string, string>::iterator it;
void init()
{
st.clear();
}
bool cmp(string e1, string e2) { return e1<e2; }
bool flag;
int main()
{
init();
while(cin>>a)
{
if(a=="XXXXXX") break;
st[a]=a;
sort(st[a].begin(), st[a].end());
}
while(cin>>b)
{
if(b=="XXXXXX") break;
sort(b.begin(), b.end());
flag=false;
for(it=st.begin(); it!=st.end(); it++)
{
if(it->second==b)
{
flag=true;
cout<<it->first<<endl;
}
}
if(!flag) printf("NOT A VALID WORD\n");
printf("******\n");
}
return 0;
}