Word Amalgamation 【HDU
阿新 • • 發佈:2018-12-15
題目連結
題意:我們先給出一系列基礎字串,之後用“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; }