Santa Claus and Keyboard Check (字符串)

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.

Example

Input

helloworld
ehoolwlroz

Output

3
h e
l o
d z

Input

hastalavistababy
hastalavistababy

Output

0

Input

merrychristmas
christmasmerry

Output

-1
 
 
#include <iostream> #include <cstdio> #include <cmath> #include <queue> #include <stack> #include <map> #include <algorithm> #include <vector> #include <string> #include <cstring> #include <sstream> #define INF 100000000 using namespace std; char a[10000]; char b[10000]; int M[1000]; struct DATA { char x,y; DATA(char xx,char yy) { x=xx; y=yy; } }; typedef struct DATA DATA; vector<DATA> ans; int main() { gets(a); gets(b); int len=strlen(a); int WA=0; for(int i=0;i<len;i++) { if(a[i]!=b[i]) { if(M[a[i]]==0 && M[b[i]]==0) { M[a[i]]=b[i]; M[b[i]]=a[i]; DATA tmp(a[i],b[i]); ans.push_back(tmp); } else if(M[a[i]]==b[i] && M[b[i]]==a[i]) { } else { WA=1; break; } } else { if(M[a[i]]==0) { M[a[i]]=a[i]; } else if(M[a[i]]!=a[i]) { WA=1; break; } } } if(WA==1) { printf("-1\n"); return 0; } printf("%d\n",ans.size()); for(int i=0;i<ans.size();i++) { printf("%c %c\n",ans[i].x,ans[i].y); } return 0; } 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值