fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5. int main()
  6. {
  7. vector<char> allLettersToCompare;
  8. vector<char> lettersFromTestCases;
  9. ios_base::sync_with_stdio(0);
  10. string wordToCompare, testWord;
  11. int testCases, amountOfAnagrams = 0, temp = 0;
  12. cin >> wordToCompare >> testCases;
  13. for (int i = 0; i < wordToCompare.length(); i++)
  14. {
  15. allLettersToCompare.push_back(wordToCompare[i]);
  16. }
  17. sort(allLettersToCompare.begin(), allLettersToCompare.end());
  18. while (testCases--)
  19. {
  20. cin >> testWord;
  21. for (int a = 0; a < testWord.length(); a++)
  22. {
  23. lettersFromTestCases.push_back(testWord[a]);
  24. }
  25. sort(lettersFromTestCases.begin(), lettersFromTestCases.end());
  26.  
  27. for (int m = 0; m < allLettersToCompare.size(); m++)
  28. {
  29. for (int k = 0; k < allLettersToCompare.size(); k++)
  30. {
  31. if (allLettersToCompare[m] == lettersFromTestCases[k])
  32. {
  33. temp++;
  34. }
  35. }
  36. }
  37. if (temp == allLettersToCompare.size())
  38. {
  39. amountOfAnagrams++;
  40. }
  41. temp = 0;
  42. lettersFromTestCases.clear();
  43. }
  44. cout << amountOfAnagrams << endl;
  45. }
Success #stdin #stdout 0.01s 5568KB
stdin
algorytm 4
samolot
logarytm
rytmolgi
morgatyl
stdout
2