Guest User

Untitled

a guest
Jul 23rd, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. // Complete the checkMagazine function below.
  2. void checkMagazine(vector<string> magazine, vector<string> note) {
  3. std::map<std::string, int> mapM, mapN;
  4. for(auto itM : magazine) {
  5. if ( mapM.find(itM) == mapM.end() ) {
  6. mapM.insert(std::make_pair(itM, 1));
  7. }
  8. else {
  9. mapM[itM]++;
  10. }
  11. }
  12. for(auto itN : note) {
  13. if ( mapN.find(itN) == mapN.end() ) {
  14. mapN.insert(std::make_pair(itN, 1));
  15. }
  16. else {
  17. mapN[itN]++;
  18. }
  19. }
  20.  
  21. for(auto it : mapN) {
  22. // Note에 있는게 Magazine에 없다면 No
  23. auto itM = mapM.find(it.first);
  24. if ( itM == mapM.end() ) {
  25. cout << "No" << endl;
  26. return;
  27. }
  28. else {
  29. if ( it.second > itM->second ) {
  30. cout << "No" << endl;
  31. return;
  32. }
  33. }
  34. }
  35. cout << "Yes" << endl;
  36. return;
  37. }
Add Comment
Please, Sign In to add comment