Skip to content

Instantly share code, notes, and snippets.

@Sharma96 Sharma96/qw.cpp
Created Sep 17, 2017

Embed
What would you like to do?
#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
You can’t perform that action at this time.