752B. Santa Claus and Keyboard Check

 

Problem Link

#Solution

 

#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair

vector<pair<char,char>>res;
#define pb push_back
map<char,int>chk;
int main()
{

    string a,b;
    cin>>a>>b;
    if(a==b)
    {cout<<0<<endl;
        return 0;
    }
for(int i=0;i<a.size();i++)
{
    if(a[i]!=b[i])
    {
        res.pb(mp(a[i],b[i]));
        char c=b[i];
        if(chk[c]||chk[a[i]])

        {
            cout<<-1;

            return 0;
        }
        chk[c]=chk[a[i]]=1;
        for(int j=0;j<a.size();j++)
        {
            if(b[j]==a[i]) b[j]=c;
            else if(b[j]==c)  b[j]=a[i];//Replacing letters

        }
    }

}
    if(a!=b)
    {
        cout<<-1;
        return 0;
    }
    cout<<res.size()<<endl;
for(int i=0;i<res.size();i++)
    cout<<res[i].first<<" "<<res[i].second<<endl;
}
Advertisements

About waprogramming

I am in CSE,from CUET
This entry was posted in Codeforces, Uncategorized and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s