-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathE0054.cpp
More file actions
40 lines (36 loc) · 669 Bytes
/
E0054.cpp
File metadata and controls
40 lines (36 loc) · 669 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
Problem Statement: https://www.hackerrank.com/challenges/making-anagrams/problem
*/
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int makingAnagrams(string s1, string s2) {
size_t pos;
int count = 0;
for(int i=s1.length()-1 ; i>=0 ; i--){
pos = s2.find(s1[i]);
if(pos == string::npos)
count++;
else
s2.erase(pos, 1);
s1.erase(i, 1);
}
for(int i=s2.length()-1 ; i>=0 ; i--){
pos = s1.find(s2[i]);
if(pos == string::npos)
count++;
else
s1.erase(pos, 1);
s2.erase(i, 1);
}
return count;
}
int main()
{
string s1, s2;
getline(cin, s1);
getline(cin, s2);
cout<<makingAnagrams(s1, s2);
return 0;
}