Advertisement
K_Y_M_bl_C

Untitled

Dec 25th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. string s, s1;
  2. int p[26];
  3. vector<pair <char, char> > ans;
  4.  
  5. int solve()
  6. {
  7.     forn(i, 26)
  8.         p[i] = i;
  9.     cin >> s >> s1;
  10.     forn(i, s.size())
  11.     {
  12.         if (s[i] == s1[i])
  13.         {
  14.             if (p[s[i] - 'a'] != s[i] - 'a')
  15.                 puts("-1"), exit(0);
  16.         }
  17.         else
  18.         {
  19.             if (p[s[i] - 'a'] == s[i] - 'a' && p[s1[i] - 'a'] == s1[i] - 'a')
  20.             {
  21.                 p[s[i] - 'a'] = s1[i] - 'a';
  22.                 p[s1[i] - 'a'] = s[i] - 'a';
  23.                 ans.inb(mk(s[i], s1[i]));
  24.             }
  25.             else
  26.             {
  27.                 if (p[s[i] - 'a'] != s1[i] - 'a' || p[s1[i] - 'a'] != s[i] - 'a')
  28.                     puts("-1"), exit(0);
  29.             }
  30.         }
  31.     }
  32.     cout << ans.size() << "\n";
  33.     forn(i, ans.size())
  34.         cout << ans[i].X << " " << ans[i].Y << "\n";
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement