Advertisement
juanjo12x

UVA_454_Anagrams

Aug 15th, 2014
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <cstring>
  5. #include <string>
  6. #include <cctype>
  7. #include <stack>
  8. #include <queue>
  9. #include <list>
  10. #include <vector>
  11. #include <map>
  12. #include <set>
  13. #include <sstream>
  14. #include <stdlib.h>
  15. #include <cmath>
  16. #define FOR(i,A) for(typeof (A).begin() i = (A).begin() ; i != (A).end() ; i++)
  17. #define debug( x ) cout << #x << " = " << x << endl
  18. #define clr(v,x) memset( v, x , sizeof v )
  19. #define all(x) (x).begin() , (x).end()
  20. #define rall(x) (x).rbegin() , (x).rend()
  21. #define TAM 110
  22. #define FOI(i, A, B) for(i=A; i<=B; i++)
  23. #define FOD(i, A, B) for(i=A; i>=B; i--)
  24. using namespace std;
  25.  
  26. typedef pair<int,int> ii ;
  27. typedef long long ll ;
  28. typedef long double ld ;
  29. typedef pair<int,ii> pii ;
  30.  
  31. string rem(string S){
  32.     sort(S.begin(), S.end());
  33.     int L = S.length() - 1, i;
  34.     string R = "";
  35.     FOI(i, 0, L)
  36.         if (!isspace(S[i]))
  37.             R += S[i];
  38.     return R;
  39. }
  40.  
  41. int main(){
  42.  
  43.     int T;
  44.     cin >> T;
  45.     string str;
  46.     getline(cin, str); getline(cin, str);
  47.     while (T--){
  48.         vector< string > V;
  49.         map<string, string> Map;
  50.         while (getline(cin, str)){
  51.             if (str == "")
  52.                 break;
  53.             V.push_back(str);
  54.             Map[str] = rem(str);
  55.         }
  56.         sort(V.begin(), V.end());
  57.         int SZ = V.size() - 1;
  58.         int i, j;
  59.         FOI(i, 0, SZ)
  60.             FOI(j, i+1, SZ)
  61.                 if (Map[V[i]] == Map[V[j]])
  62.                     cout << V[i] << " = " << V[j] << endl;
  63.         if (T)
  64.             cout << endl;
  65.     }
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement