首页 > 其他 > 详细

[ZOJ 1006] Do the Untwist (模拟实现解密)

时间:2014-11-12 22:46:55      阅读:219      评论:0      收藏:0      [点我收藏+]

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=6

题目大意:给你加密方式,请你求出解密。

 

直接逆运算搞,用到同余定理

 

 1 #include <cstdio>
 2 #include <cstdlib>
 3 #include <string>
 4 #include <iostream>
 5 #include <cstring>
 6 #include <algorithm>
 7 #include <cctype>
 8 #include <vector>
 9 #include <map>
10 #include <set>
11 #include <iterator>
12 #include <functional>
13 #include <cmath>
14 #include <numeric>
15 using namespace std;
16 typedef long long LL;
17 typedef pair<int,int> PII;
18 typedef vector<int> VI;
19 #define PB push_back
20 #define MP make_pair
21 #define SZ size()
22 #define CL clear()
23 #define AA first
24 #define BB second
25 #define EPS 1e-8
26 #define ZERO(x) memset((x),0,sizeof(x))
27 const int INF = ~0U>>1;
28 const double PI = acos(-1.0);
29 
30 int get_num(char c){
31     if( c==_ ) return 0;
32     if( c==.) return 27;
33     return c-a+1;
34 }
35 
36 char get_char(int n){
37     if( n==0 ) return _;
38     if( n==27 ) return .;
39     return n+a-1;
40 }
41 
42 int main(){
43     int k;
44     while( scanf("%d",&k),k ){
45         char buff[100];
46         scanf("%s",buff);
47         int plaincode[100],ciphercode[100];
48         ZERO(plaincode); ZERO(ciphercode);
49         int n = strlen(buff);
50         for(int i=0;i<n;i++){
51             ciphercode[i] = get_num(buff[i]);
52         }
53         for(int i=0;i<n;i++){
54             plaincode[(k*i)%n] = (ciphercode[i] + i)%28;
55         }
56         for(int i=0;i<n;i++){
57             putchar(get_char(plaincode[i]));
58         }
59         puts("");
60     }
61     return 0;
62 }

 

[ZOJ 1006] Do the Untwist (模拟实现解密)

原文:http://www.cnblogs.com/llkpersonal/p/4093579.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!