Codeforces Round #389 Div.2 B. Santa Claus and Keyboard Check

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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

 

开个link数组,判断字符与字符间的对应关系。

如果所有不同的字符对都满足双向对应,那么有解。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<cstring>
 5 #include<queue>
 6 using namespace std;
 7 const int mxn=1010;
 8 int read(){
 9     int x=0,f=1;char ch=getchar();
10     while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
11     while(ch>='0' && ch<='9'){x=x*10-'0'+ch;ch=getchar();}
12     return x*f;
13 }
14 char link[mxn];
15 char s[mxn];
16 char c[mxn];
17 int k=0;
18 char ans1[mxn],ans2[mxn];
19 bool vis[mxn];
20 int main(){
21     int i,j;
22     scanf("%s%s",s,c);
23     int len=strlen(s);
24     if(len!=strlen(c)){printf("-1\n");return 0;}
25     for(i=0;i<len;i++){
26         if(c[i]!=link[s[i]]){
27             if(!link[s[i]]){
28                 link[s[i]]=c[i];
29             }
30             else{printf("-1\n");return 0;}
31         }
32         if(s[i]!=link[c[i]]){
33             if(!link[c[i]]){
34                 link[c[i]]=s[i];
35             }
36             else {printf("-1\n");return 0;}
37         }
38     }
39     for(i=0;i<26;i++){
40         int tmp='a'+i;
41         if(!link[tmp])continue;
42         if(link[tmp]!=tmp && !vis[tmp]){
43             ans1[++k]=tmp;
44             ans2[k]=link[tmp];
45             vis[tmp]=vis[link[tmp]]=1;
46         }
47     }
48     printf("%d\n",k);
49     for(i=1;i<=k;i++){
50         printf("%c %c\n",ans1[i],ans2[i]);
51     }
52     return 0;
53 }

 

 

 

转载于:https://www.cnblogs.com/SilverNebula/p/6224282.html

已经博主授权,源码转载自 https://pan.quark.cn/s/e577710b7191 ### 解决Win10系统中Word文件图标显示不正常问题 #### 问题描述 在Windows 10操作系统中,部分用户遇到Word文档图标呈现非正常状态的问题。具体表现为:本应展示为Microsoft Word图标的DOC或DOCX文件,在系统中却呈现为常规的文本文件图标。这种现象不仅降低了用户的视觉体验,还可能引发一定的操作不便。 #### 解决方案 ##### 方法一:借助注册表编辑来纠正图标显示异常 1. **进行注册表备份**:为了保障系统的稳定性,在开展任何注册表修改之前,必须对注册表进行备份。可以通过“导出”功能来达成备份目的。 - 启动“运行”对话框(快捷键:`Windows + R`),键入`regedit`,随后按回车键进入注册表编辑界面。 - 在注册表编辑界面中,找到菜单栏里的“文件”选项,点击后选择“导出”,依照提示完成注册表备份。 2. **移除相关注册表项**: - 在`HKEY_CLASSES_ROOT`下,删除以下四个注册表项: - `.doc` - `.docx` - `Word.Document.8` - `Word.Document.12` - 在`HKEY_LOCAL_MACHINE\SOFTWARE\Classes`下,同样移除上述四个注册表项。 3. **重新启动计算机**:执行完上述步骤后,重新启动计算机以使修改生效。 #### 方法二:通过调整文件关联来纠正图标显示异常 如果第一种方法未能解决难题,则可以尝试调整文件的关联方式,具体步骤如下: 1. **移除文件关联**: - 在`HKEY_CLASSES_ROOT`下删除`....
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值