solved hackerrank's hash table ransom note

Signed-off-by: ayham <altffour@protonmail.com>
This commit is contained in:
ayham 2021-05-13 09:47:00 +03:00
parent 1091b6727a
commit f39777f6a2
No known key found for this signature in database
GPG Key ID: 81D38F7122AFCC94
1 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1,25 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.sync_with_stdio(false);
int m, n, num = 0;
map<string, int> magazine;
cin >> m >> n;
while (m--) {
string mag;
cin >> mag;
if (magazine[mag] <= 0) magazine[mag] = 1;
else magazine[mag]++;
}
for (int i = 0; i < n; i++) {
string note;
cin >> note;
if (magazine.find(note) != magazine.end() && (magazine[note]--) != 0) num++;
}
cout << ((num == n) ? "Yes" : "No") << endl;
return 0;
}