Description

Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be.

In order to make sure that he's right and restore the correct order of keys, Santa typed his favorite patter looking only to his keyboard.

You are given the Santa's favorite patter and the string he actually typed. Determine which pairs of keys could be mixed. Each key must occur in pairs at most once.

Input

The input consists of only two strings s and t denoting the favorite Santa's patter and the resulting string. s and t are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters.

Output

If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes).

Otherwise, the first line of output should contain the only integer k (k ≥ 0) — the number of pairs of keys that should be swapped. The following k lines should contain two space-separated letters each, denoting the keys which should be swapped. All printed letters must be distinct.

If there are several possible answers, print any of them. You are free to choose the order of the pairs and the order of keys in a pair.

Each letter must occur at most once. Santa considers the keyboard to be fixed if he can print his favorite patter without mistakes.

Examples
input
helloworld
ehoolwlroz
output
3
h e
l o
d z
input
hastalavistababy
hastalavistababy
output
0
input
merrychristmas
christmasmerry
output
-1

题意:给两个字符串,它们有如样列一样的性质,输出不一样的字母对,注意

ab

aa

不是输出

1

a b

而是-1,因为a,b不成替代关系(第一个字符a==第二个字符a)

解法:自然是依次遍历,找出不同点标记下来,注意相同的情况

#include <bits/stdc++.h>
using namespace std;
int ans=,k=,vis[];
char x[],y[];
map<char,char>q;
string s1,s2;
map<char,char>::iterator it;
int main()
{
cin>>s1>>s2;
int num=;
for(int i=; i<s1.length(); i++)
{
if(s1[i]!=s2[i])
{
if(q.find(s1[i])==q.end()&&q.find(s2[i])==q.end())
{
q[s1[i]]=s2[i];
q[s2[i]]=s1[i];
}
else if(q[s1[i]]!=s2[i]||q[s2[i]]!=s1[i])
{
cout<<"-1"<<endl;
return ;
}
}
else
{
if(q.find(s1[i])==q.end())
{
q[s1[i]]=s1[i];
num++;
}
else if(q[s1[i]]!=s1[i])
{
cout<<"-1"<<endl;
return ;
}
}
}
cout<<(q.size()-num)/<<endl;
for(it=q.begin(); it!=q.end(); it++)
{
char ch1=it->first,ch2=it->second;
if(vis[ch1-'a']==||vis[ch2-'a']==||ch1==ch2) continue;
cout<<ch1<<" "<<ch2<<endl;
vis[ch1-'a']=,vis[ch2-'a']=;
}
return ;
}

Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) B的更多相关文章

  1. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) C

    Description Santa Claus has Robot which lives on the infinite grid and can move along its lines. He ...

  2. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) A

    Description Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the f ...

  3. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) D. Santa Claus and a Palindrome STL

    D. Santa Claus and a Palindrome time limit per test 2 seconds memory limit per test 256 megabytes in ...

  4. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) E. Santa Claus and Tangerines

    E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  5. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) 圣诞之夜!

    A. Santa Claus and a Place in a Class 模拟题.(0:12) 题意:n列桌子,每列m张桌子,每张桌子一分为2,具体格式看题面描述.给出n,m及k.求编号为k的桌子在 ...

  6. Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)

    http://codeforces.com/contest/737 A: 题目大意: 有n辆车,每辆车有一个价钱ci和油箱容量vi.在x轴上,起点为0,终点为s,中途有k个加油站,坐标分别是pi,到每 ...

  7. codeforces Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)// 二分的题目硬生生想出来ON的算法

    A. Road to Cinema 很明显满足二分性质的题目. 题意:某人在起点处,到终点的距离为s. 汽车租赁公司提供n中车型,每种车型有属性ci(租车费用),vi(油箱容量). 车子有两种前进方式 ...

  8. Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2) E. Subordinates 贪心

    E. Subordinates time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  9. Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2) D. Sea Battle 模拟

    D. Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input ...

随机推荐

  1. scala中的集合框架

  2. iOS JavaScriptCore与H5交互时出现异常提示

    在利用JavaScriptCore与H5交互时出现异常提示: This application is modifying the autolayout engine from a background ...

  3. Python开发【前端】:汇总

    页面模板 1.EasyUI(推荐指数★) JQuery EasyUI中文网 下载 使用方法:把文件下载到本地.直接从官网上把源码拷贝过来,更改下js的路径即可 优点:功能非常多.非常齐全 偏做后台管理 ...

  4. 五句话搞定JavaScript作用域

    JavaScript的作用域一直以来是前端开发中比较难以理解的知识点,对于JavaScript的作用域主要记住几句话,走遍天下都不怕... 一.“JavaScript中无块级作用域” 在Java或C# ...

  5. GCD的简单用法

    /* 创建一个队列用来执行任务,TA属于系统预定义的并行队列即全局队列,目前系统预定义了四个不同运行优先级的全局队列,我们可以通过dispatch_get_global_queue来获取它们 四种优先 ...

  6. iPhone CSS media query(媒体查询)

    iPhone5  iPhone6  iPhone6Plus iPad设备 media query(媒体查询)代码. iPhone < 5: @media screen and (device-a ...

  7. Caused by: java.sql.SQLException: ORA-00918: column ambiguously defined

    外层t.*的时候,可能发现重复字段,所以检查内层的sql是否出现了重复字段的查询.

  8. 记一次MVC4站点在IIS上部署的诡异问题

    最近朋友的公司遇到一个站点部署问题, 朋友从事服务器维护多年,说也是花了十多天仍为解决. 经多次尝试未果,仍报错如下: 我询问了相关情况,确认了该网站是VS2013开发的,版本为,NET Framew ...

  9. IIS无法加载字体文件(*.woff,*.svg)的解决办法

    在编写前端代码的过程中经常会遇到使用特定的字体(*.woff,*.svg),此时在加载字体时请求会被返回 Failed to load resource: the server responded w ...

  10. JavaScript在A页面判断B页面加载完毕(iframe load)

    今天遇到一个需求,在A页面上判断B页面是否加载完毕(B页面是第三方页面),加载完毕时隐藏loading动画... 而平时我们一般做的事是在B页面上判断B页面是否加载完毕,进行操作. if(docume ...