Guest User

Untitled

a guest
Jul 23rd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. vector<string> split_string(string);
  6.  
  7. // Complete the checkMagazine function below.
  8. void checkMagazine(vector<string> magazine, vector<string> note) {
  9. for(auto itN = note.begin(); itN != note.end(); ) {
  10. bool bFind = false;
  11. for(auto itM = magazine.begin(); itM != magazine.end(); ) {
  12. if ( *itN == *itM ) {
  13. itM = magazine.erase(itM);
  14. bFind = true;
  15. break;
  16. }
  17. ++itM;
  18. }
  19. if ( bFind == true ) {
  20. itN = note.erase(itN);
  21. }
  22. else {
  23. cout << "No" << endl;
  24. return;
  25. }
  26. }
  27. cout << "Yes" << endl;
  28. return;
  29. }
  30.  
  31. int main()
  32. {
  33. string mn_temp;
  34. getline(cin, mn_temp);
  35.  
  36. vector<string> mn = split_string(mn_temp);
  37.  
  38. int m = stoi(mn[0]);
  39.  
  40. int n = stoi(mn[1]);
  41.  
  42. string magazine_temp_temp;
  43. getline(cin, magazine_temp_temp);
  44.  
  45. vector<string> magazine_temp = split_string(magazine_temp_temp);
  46.  
  47. vector<string> magazine(m);
  48.  
  49. for (int i = 0; i < m; i++) {
  50. string magazine_item = magazine_temp[i];
  51.  
  52. magazine[i] = magazine_item;
  53. }
  54.  
  55. string note_temp_temp;
  56. getline(cin, note_temp_temp);
  57.  
  58. vector<string> note_temp = split_string(note_temp_temp);
  59.  
  60. vector<string> note(n);
  61.  
  62. for (int i = 0; i < n; i++) {
  63. string note_item = note_temp[i];
  64.  
  65. note[i] = note_item;
  66. }
  67.  
  68. checkMagazine(magazine, note);
  69.  
  70. return 0;
  71. }
  72.  
  73. vector<string> split_string(string input_string) {
  74. string::iterator new_end = unique(input_string.begin(), input_string.end(), [] (const char &x, const char &y) {
  75. return x == y and x == ' ';
  76. });
  77.  
  78. input_string.erase(new_end, input_string.end());
  79.  
  80. while (input_string[input_string.length() - 1] == ' ') {
  81. input_string.pop_back();
  82. }
  83.  
  84. vector<string> splits;
  85. char delimiter = ' ';
  86.  
  87. size_t i = 0;
  88. size_t pos = input_string.find(delimiter);
  89.  
  90. while (pos != string::npos) {
  91. splits.push_back(input_string.substr(i, pos - i));
  92.  
  93. i = pos + 1;
  94. pos = input_string.find(delimiter, i);
  95. }
  96.  
  97. splits.push_back(input_string.substr(i, min(pos, input_string.length()) - i + 1));
  98.  
  99. return splits;
  100. }
Add Comment
Please, Sign In to add comment