Created
September 17, 2017 18:21
-
-
Save Sharma96/a2c106b702890c271761b4f645072d47 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<string> | |
#include<utility> | |
#include<unordered_map> | |
#include<map> | |
using namespace std; | |
bool is_per(string s, string s1) { | |
if (s.length() != s1.length()) { | |
//cout << "sdfg"; | |
return false; | |
} | |
if (s == s1) { | |
return true; | |
} | |
unordered_map<char, int> m1, m2; | |
for (int i = 0; s[i] != '\0'; i++) { | |
if (m1.find(s[i]) != m1.end()) { | |
//cout << s[i] << " < -- " << endl; | |
m1[s[i]]++; | |
} | |
else { | |
m1.insert({ s[i],1 }); | |
} | |
} | |
for (int i = 0; s1[i] != '\0'; i++) { | |
if (m2.find(s1[i]) != m2.end()) { | |
//cout << s[i] << " < -- " << endl; | |
m2[s1[i]]++; | |
} | |
else { | |
m2.insert({ s1[i],1 }); | |
} | |
} | |
unordered_map<char, int>::iterator it1, it2; | |
for (int i = 0; s[i] != '\0'; i++) { | |
it1 = m1.find(s[i]); | |
it2 = m2.find(s1[i]); | |
if ((it1 != m1.end() && it2 == m2.end()) || (it1 == m1.end() && it2 != m2.end())) { | |
// cout << s[i] << " and " << s1[i] << endl; | |
return false; | |
} | |
if (it1->second == it2->second) { | |
// cout << it1->first << " " << it1->second << endl; | |
continue; | |
} | |
else { | |
return false; | |
} | |
} | |
return true; | |
} | |
int main() { | |
int n; | |
cin >> n; | |
int n1 = 1; | |
unordered_map<int, string> m; | |
while (n1 <= n) { | |
int x; | |
string s; | |
cin >> x; | |
cin.ignore(); | |
getline(cin, s); | |
if (m.find(x) == m.end()) { | |
m.insert({ x,s }); | |
} | |
n1++; | |
} | |
int ans_ = 0; | |
n1 = 1; | |
while (n1 <= n) { | |
int x; | |
string s; | |
cin >> x >> s; | |
unordered_map<int, string>::iterator it; | |
it = m.find(x); | |
string ss = it->second; | |
if (!is_per(s, ss)) { | |
//cout << s << " " << ss << endl; | |
ans_++; | |
} | |
n1++; | |
} | |
cout << ans_ << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment