2019杭州师范大学校赛 I-题Little Sub and Enigma

问题 I: Little Sub and Enigma
时间限制: 1 Sec 内存限制: 256 MB
提交: 807 解决: 73
[提交] [状态] [命题人:admin]
题目描述
Little Sub builds a naive Enigma machine of his own. It can only be used to encrypt/decrypt lower-case letters by giving each letter a unique corresponding lower-case letter. In order to ensure the accuracy, no contradiction or controversy is allowed in both the decryption and the encryption, which means all lower-case letters can only be decrypted/encrypted into a distinct lower-case letter.
Now we give you a string and its encrypted version. Please calculate all existing corresponding relationship which can be observed or deducted through the given information.

输入
The first line contains a string S, indicating the original message.
The second line contains a string T, indicating the encrypted version.
The length of S and T will be the same and not exceed 1000000.

输出
we use a string like ’x->y’ to indicate that letter x will be encrypted to letter y.
Please output all possible relationships in the given format in the alphabet order.
However, if there exists any contradiction in the given information, please just output Impossible in one line.

样例输入
复制样例数据
banana
cdfdfd
样例输出
a->d
b->c
n->f

思路;对于小写字母x和y有x->y进行加密,加密要满足一一映射,问能不能满足,能就按字典序输出对应的映射关系,不能就输出impossible,这里需要注意的是输出有一个坑,输出要求是根据已知条件推断出所有能够对应的映射关系,当有25个字母完成对应后,那么第26个就可以推断出来,所以要输出26个,知道这个就很好写了

#include<bits/stdc++.h>
using namespace std;
typedef struct{
	int a;
	int b;
}xxx;
xxx x[26];
int vis[26];      **//vis记录s1的小写字母**
int vis2[26];    **//vis2记录s2的小写字母**
char s1[1000005];
char s2[1000005];
int main()
{
	cin>>s1>>s2;
	int len = strlen(s1);
	int flag = 1,flag2=1,flag3=0;
	for (int i = 0; i < len; i++)
	{
		if(s1[i]>='a'&&s2[i]<='z')
		{
			int t = s1[i] - 'a';
			int t2 = s2[i] - 'a';
			if (vis[t] == 0){
				x[t].a = t;
				x[t].b = t2;
				vis[t] = 1;
				vis2[t2]++;flag3++;
			}
			if (x[t].b != t2){
				flag = 0;
			}
			if (vis2[t2] > 1){
				flag2 = 0;
			}
		}
	}
	if (flag&&flag2)
	{
		for (int i = 0; i < 26; i++)
		{
			if (vis[i] == 1)
			{
				printf("%c->%c\n", x[i].a + 'a', x[i].b + 'a');
			}
			if(flag3==25){
				if(vis[i]==0)
				{
					int j;
					for(int i=0;i<26;i++){
						if(vis2[i]==0){
							j=i;break;
						}
					}
					printf("%c->%c\n", i + 'a', j + 'a');
				}
			}
		}
	}
	else{
		cout << "Impossible\n";
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值