Show/Hide Code
//Headers #include <set> #include <map> #include <list> #include <cmath> #include <ctime> #include <deque> #include <queue> #include <stack> #include <cctype> #include <cstdio> #include <string> #include <vector> #include <cassert> #include <cstdlib> #include <cstring> #include <sstream> #include <iostream> #include <algorithm> #include <climits> #include <clocale> //Defines #define pow2(i) (1<<i) #define bit(i) (1<<i) #define isOdd(i) (i&1) #define isEven(i) (!(i&1)) #define isPrime(i) ((i==2) || ((i&1) && !pTest[i])) //pTest has to be the bool array's name #define sz(i) i.size() #define vec(type,name) vector< type > name #define rep(i,a,b) for(int i=a ; i<=b ; i++) #define swap(type,a,b) {type t=a; a=b; b=t;} #define sum(a,n) ( (n*(n+1)/2) - (a-1)*a/2 ) #define iscap(i) (i>='A'&&i<='Z') #define issmall(i) (i>='a'&&i<='z') #define isnum(i) (i>='0'&&i<='9') #define issymbol(i) (!(i>='a'&&i<='z') && !(i>='A'&&i<='Z') && !(i>='0'&&i<='9')) #define mk(i,j) make_pair(i,j) #define ERROR 1e-11 //Type Defs typedef long long lint; typedef unsigned long long ulint; typedef long double ldouble; using namespace std; multimap<string, string> mp; bool cmp(string a, string b) { return (a<b); } int main() { int i; string dc, st; vector<string> lst; multimap<string,string>::iterator it, xt; pair<multimap<string,string>::iterator, multimap<string,string>::iterator> ret; while ( cin >> dc ) { if (dc == "XXXXXX") break; st = dc; sort(dc.begin(),dc.end()); //cout << "STORING: " << dc << endl; mp.insert(pair<string,string>(dc,st)); } while ( cin >> dc ) { if (dc == "XXXXXX") break; sort(dc.begin(),dc.end()); if ((int)mp.count(dc) == 0) cout << "NOT A VALID WORD" << endl; else { ret = mp.equal_range(dc); lst.clear(); for (it=ret.first ; it!=ret.second ; ++it) { lst.push_back((*it).second); } sort(lst.begin(),lst.end()); for (i=0 ; i<lst.size() ; i++) { cout << lst[i] << endl; } } cout << "******" << endl; } // TEST CASE // int kase=1, kounter=1; //freopen("input.txt","r",stdin); //freopen("outptu.txt","w+",stdout); return 0; }
No comments:
Post a Comment
Post your comment here. If you want to say something about programming problems, scripts, software etc, please try to be as descriptive as possible.