fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <cctype>
  4. using namespace std;
  5.  
  6. string s1,s2;
  7. int tc;
  8.  
  9. int main(void)
  10. {
  11. cin >> tc;
  12. while(tc--) {
  13. cin >> s1 >> s2;
  14. int match = 0;
  15. for(int i=0; i<s1.length(); i++){
  16. for(int j=0; j<s2.length(); j++) {
  17. if(toupper(s1[i])==toupper(s2[j])){
  18. match++;
  19. break;
  20. }
  21. }
  22. }
  23. cout << s1 << " & " << s2 << " are ";
  24. if(match==s1.length()) cout << "anagrams.";
  25. else cout << "NOT anagrams.";
  26. cout << "\n";
  27. }
  28. return 0;
  29. }
  30.  
Success #stdin #stdout 0s 15232KB
stdin
1
a aa
stdout
a & aa are anagrams.