Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <set>
- using namespace std;
- bool find(vector <string> &c, string s) {
- for (int i = 0; i < c.size(); i++)
- if (c[i] == s)
- return true;
- return false;
- }
- int main() {
- int k, n;
- cin >> k >> n;
- vector<string> c;
- set <char> set1;
- set <char> set2;
- for (int i = 0; i < n; i++) {
- string s;
- cin >> s;
- c.push_back(s);
- }
- string str1, str2;
- string s1;
- string s2;
- cin >> str1 >> str2;
- set1.insert(str1.begin(), str1.end());
- set2.insert(str2.begin(), str2.end());
- if (str1.size() != str2.size() || set1 != set2) {
- cout << "NO";
- return 0;
- }
- for (char c1 = 'a'; c1 < 'j'; c1++) {
- for (char c2 = c1 + 1; c2 < 'j'; c2++) {
- string s = { c1, c2 };
- if (find(c, s))
- continue;
- else {
- s1 = "";
- s2 = "";
- for (int i = 0; i < str1.size(); i++) {
- if (str1[i] == c1 || str1[i] == c2)
- s1.push_back(str1[i]);
- if (str2[i] == c1 || str2[i] == c2)
- s2.push_back(str2[i]);
- }
- if (s1 != s2) {
- cout << "No";
- return 0;
- }
- }
- }
- }
- cout << "Yes";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement