poj Permutation Code (模拟)
来源:互联网 发布:sql 时间转换 编辑:程序博客网 时间:2024/05/23 05:07
题意:给定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;}
- poj Permutation Code (模拟)
- poj 2015 Permutation Code
- POJ 2015 Permutation Code
- poj 2015 Permutation Code
- POJ2015 Permutation Code
- poj2015-Permutation Code
- CODE 73: Permutation Sequence
- CODE 102: Next Permutation
- [leet code] Next Permutation
- 2404 Permutation Recovery【模拟】
- POJ 1780 Code(欧拉回路+模拟栈)
- poj 2629 Common permutation
- POJ 2629:Common permutation
- CSU1977-Bit-reversal Permutation-模拟
- Code POJ
- Code POJ
- POJ 3785 The Next Permutation
- leetcode 日经贴,python code -Next Permutation
- js搜索本页中的内容
- java 标签 查找一个数是否在数组内
- eclipse的console无法正确显示ANSI的颜色字体的问题
- [MySQL] ERROR 2002(HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.
- Cannot open source file: 'C:\Program Files\Microsoft Visual Studio\VC98\MFC\SRC\APPMODUL.CPP': No
- poj Permutation Code (模拟)
- 黑马程序员——浅谈java中的内部类<三>
- 整型数组处理算法(九)给定任意一个正整数,求比这个数大且最小的“不重复数”(性能优化)[2014百度笔试题]
- 形形色色的软件生命周期模型(4)——MSF、实用型
- GDI+真难用
- 央视爆光微信打飞机流量门事件的思考
- MySQL 中文显示乱码
- popover典型问题:Popover with embedded navigation controller doesn't respect size on back nav
- MIPS Address Space