Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <algorithm>
- #include <string>
- #include <cstring>
- #include <vector>
- #include <cstdio>
- #include <map>
- #include <utility>
- #include <queue>
- #include <stack>
- #include <deque>
- #include <iomanip>
- #include <set>
- #include <fstream>
- #include <ctime>
- #include <cstdlib>
- #define INF (1<<30)
- #define F first
- #define S second
- #define pb push_back
- #define mp make_pair
- #define ll long long
- #define ld long double
- #define lld long long double
- #define pii pair<ll,ll>
- #define mod 1000000007
- #define endl '\n'
- #define BYKKKSGIUT
- // меняй все переменные
- #define TASKNAME ""
- using namespace std;
- char used['z'+100];
- int main(){
- // freopen(TASKNAME".in", "r", stdin);
- // freopen(TASKNAME".out", "w", stdout);
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- string s1,s2;
- cin >> s1;
- cin >> s2;
- int n = s1.length();
- int cnt = 0;
- for(int i = 0; i < n; i++){
- if(s1[i]!=s2[i]){
- if((used[s1[i]]!=0 && used[s1[i]]!=s2[i]) || (used[s2[i]]!=0 && used[s2[i]]!=s1[i])){
- cout << -1 << endl;
- return 0;
- }else{
- if(used[s1[i]]==0 && used[s2[i]] == 0){
- // cout << s1[i] << ' ' << s2[i] << endl;
- cnt++;
- }
- used[s1[i]] = s2[i];
- }
- }
- }
- cout << cnt << endl;
- set<char> s;
- for(char i = 'a'; i <= 'z'; i++){
- if(used[i]!=0){
- s.insert(used[i]);
- if(s.find(i) == s.end())
- cout << i << ' ' << used[i] << endl;
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment