2019年杭州师范大学第十二届程序设计竞赛 I:Little Sub and Enigma(简单思维题)

Little Sub and Enigma

【题解】

为什么那时候没有开这道题呢(沉默)

加密串与解密串的字母一一对应。输出可推断出的所有情况,特判25组对应关系推出第26组的情况。

思路:加密串对应的解密串字母一定是同时出现的,vis1[]记录加密串字母出现过与否(出现过则赋值为对应字母的ASCII码),vis2[]记录解密串字母出现过与否。定义计数器判断25->26的情况。没有一一对应就输出Impossible。

【代码】

int main()
{
    string a,b; cin>>a>>b;
    int l=a.length();
    int f=1,vis1[300]={0},vis2[300]={0};
    int c=0;
    for(int i=0;i<l;i++){
        if(vis1[a[i]]==0&&vis2[b[i]]==0){
            c++;
            vis1[a[i]]=b[i];
            vis2[b[i]]=1;
        }
        else if(vis1[a[i]]==(int)b[i]) continue;
        else{
            f=0; break;
        }
    }
    if(f){
        if(c==25){
            for(int i=97;i<97+26;i++){
                if(vis1[i]==0){
                    for(int j=97;j<97+26;j++){
                        if(vis2[j]==0){
                            vis1[i]=j;
                            break;
                        }
                    }
                    break;
                }
            }
        }
        for(int i=97;i<97+26;i++){
            if(vis1[i])
                printf("%c->%c\n",i,vis1[i]);
        }
    }
    else puts("Impossible");
    return 0;
}

【题目】

Little Sub and Enigma AC

Time Limit:  1 s      Memory Limit:   256 MB

Submission:1833     AC:112     Score:100.00

Description

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.

Input

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.

Output

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.

Samples

input:

banana

cdfdfd

output:

a->d

b->c

n->f

input:

banana

cdfdfs

output:

Impossible

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值