Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5. void sort(string& s)
  6. {
  7. int count[26] = { 0 };
  8.  
  9. for (int i = 0; i < s.size(); i++)
  10. {
  11. count[(s[i] - 'a')]++;
  12. }
  13. int t = 0;
  14. while (t < s.size())
  15. {
  16. for (int i = 0; i < 26; i++)
  17. {
  18. if (count[i] > 0)
  19. {
  20. s[t++] = ('a' + i);
  21. }
  22. }
  23. }
  24.  
  25. }
  26.  
  27. bool isEqual(string a, string b)
  28. {
  29.  
  30. for (int i = 0; i < a.length(); i++)
  31. {
  32. if (a[i] != b[i])
  33. return false;
  34. }
  35. return true;
  36.  
  37. }
  38. void first(string word1, string word2, int n)
  39. {
  40. int n1 = word1.length();
  41. int n2 = word2.length();
  42. if (n1 == 0)
  43. {
  44. cout << "yes";
  45. return;
  46. }
  47. if (n1 != n2 || n1> n || n2 > n)
  48. {
  49. cout << "no";
  50. return;
  51. }
  52. if (isEqual(word1, word2))
  53. {
  54. cout << "yes";
  55. return ;
  56. }
  57.  
  58. sort(word1);
  59. sort(word2);
  60. if (isEqual(word1, word2))
  61. {
  62. cout << "yes";
  63. return ;
  64. }
  65. cout << "no";
  66. }
  67. void testFirst()
  68. {
  69. int n = 5;
  70. cin >> n;
  71. cin.ignore();
  72.  
  73.  
  74. string word1 = "";
  75. getline(cin, word1);
  76. string word2 = "";
  77. getline(cin, word2);
  78.  
  79. first(word1, word2, n);
  80. }
  81. int main()
  82. {
  83. testFirst();
  84. cin.get();
  85. return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement