-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMake_Anagrams.cpp
More file actions
32 lines (30 loc) · 776 Bytes
/
Copy pathMake_Anagrams.cpp
File metadata and controls
32 lines (30 loc) · 776 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
#include <iostream>
using namespace std;
//WAP to determine the minimum modification I should perform so as to make two strings anagrams of each other. I am not_eq
//allowed to delete any element. Both arrays are of same size.
int main() {
// your code goes here
string s = "abc", t = "ddd";
int a[26] = {}, cnt=0;
for(int i = 0; i<26; i++){
a[s[i]-'a']++; //a[0] = 1, a[1]=1, a[2]=1;
}
for(int i = 0; i<26; i++){
a[t[i]-'a']--; // a[3]=-1 =>-2=>-3;
}
for(int i = 0; i<26; i++){
cnt += abs(a[i]);
/*
if(a[i]!=0){
cnt+=abs(a[i]);
cout<<(cnt/2);
}
if(a[i]!=0){
cnt+=abs(a[i]);
cout<<(cnt/2);
}
*/
}
cout<<(cnt/2);
return 0;
}