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. mysql小结

    1.使用密码登录mysql mysql -u root -p 2.查看所有的数据库 show databases; 3.创建数据库 create database <数据库名>; 4.创建 ...

  2. Swift:属性观察器

    1.简单介绍 属性观察器监控和响应属性值的变化,每次属性被设置值的时候都会调用属性观察器,甚至新的值和现在的值相同的时候也不例外. 可以为除了延迟存储属性之外的其他存储属性添加属性观察器,也可以通过重 ...

  3. java.lang.IllegalArgumentException: Result Maps collection does not contain value for java.lang.Integer

    今天做springmvc+mybatis+spring的项目的时候发现了一个异常.如下: org.apache.ibatis.builder.IncompleteElementException: C ...

  4. 实时控制软件设计第一周作业-汽车ABS软件系统案例分析

    汽车ABS软件系统案例分析 ABS 通过控制作用于车轮制动分泵上的制动管路压力,使汽车在紧急刹车时车轮不会抱死,这样就能使汽车在紧急制动时仍能保持较好的方向稳定性. ABS系统一般是在普通制动系统基础 ...

  5. VS2013 ViewData ViewBag Ajax等关键词报错(当前上下文不存在名称)而且不提示也点不出来,但是可以正常运行,

    这个多数问题是因为 视图 的Web.config 内的配置问题 在Views文件夹下  有一个Web.config文件,把里面的版本号(System.Web.Mvc, Version=5.2.2.0) ...

  6. 汽车ABS系统-第一周作业

    ABS系统也成防抱死系统(Anti-lock Braking System),由罗伯特·博世有限公司所开发的一种在摩托车和汽车中使用,它会根据各车轮角速度信号,计算得到车速.车轮角减速度.车轮滑移率: ...

  7. 查看https是否支持ATS

    nscurl --ats-diagnostics --verbose https://我的域名

  8. ubuntu16.04部署RED5流媒体服务器

    前提:jdk已经安装 1,下载RED5(https://github.com/Red5/red5-server/releases)选择red5-server-X.X.X-MXX.tar.gz 2,解压 ...

  9. Design and Analysis of Algorithms_Divide-and-Conquer

    I collect and make up this pseudocode from the book: <<Introduction to the Design and Analysis ...

  10. Leetcode: Serialize and Deserialize BST

    Serialization is the process of converting a data structure or object into a sequence of bits so tha ...