poj Permutation Code (模拟)

题意:给定S,P,C三个字符串,C是加密好的字符串,根据加密原理,求解原文。

 

posS,为字符在S串中的位置,posP为字符在P串中的位置。

突破口在d,相当于密钥。

然后往前循环依次得出M串的每个字符。得出在P串的位置利用了两个相同的树异或值为0的原理。

 

代码:

 

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
const int MAX_ = 100;
const int aciiMAX_ = 256;
int posS[aciiMAX_], posP[aciiMAX_];
char S[MAX_], P[MAX_], C[MAX_], M[MAX_];

int main(){
    int x, d, len, poS,poP, tmp,poC;
    while(~scanf("%d",&x),x){
        scanf("%s%s%s",S,P,C);
        for(int i = 0; S[i]; i++){
            posS[(int)S[i]] = i;
        }
        for(int i = 0; P[i]; i++){
            posP[(int)P[i]] = i;
        }
        len = strlen(C);
        d = (int)(pow(len,1.5) + x)%len;
        tmp = d;
        poS = posS[C[d]];
        M[d] = P[poS];
        tmp = (tmp - 1 + len) % len;
        while(tmp != d){
            poS = posS[M[(tmp + 1)%len]];
            poC = posS[C[tmp]];
            M[tmp] = P[poC ^ poS];
            tmp = (tmp - 1 + len) % len;
        }
        M[len] = '\0';
        printf("%s\n",M);
    }
    return 0;
}


 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值