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

题目链接: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 }
时间: 2024-10-12 16:44:25

[ZOJ 1006] Do the Untwist (模拟实现解密)的相关文章

ZOJ 1006 Do the Untwish

Do the Untwish 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1006 题意:给定密文按公式解密 注意点:pcode = (ccode + i)%28;的使用 贴代码: 1 //Problem Name: Do the Untwish 2 //Source: ZOJ 1006 3 //Author: jinjin18 4 //Main idea: easy to solve 5 //Languag

ZOJ 1111 Poker Hands --复杂模拟

昨天晚上写的,写了一个多小时,9000+B,居然1A了,爽. 题意:玩扑克,比大小.规则如下: 题意很简单,看过赌神的人都知道,每人手中5张排,比牌面大小,牌面由大到小分别是(这里花色无大小),级别从高到低依次为:1.同花顺:牌面一样,只比较最大的看谁大,一样大则平手2.四条:四个一样的,看这四个一样的中谁大谁赢3.葫芦:三条+一对,看三条中谁的牌面大4.同花:都是同花就按从大到小比较,看谁的更大5.顺子:都是顺子看最大的谁大,一样则平手6.三条:三条看三条中谁的牌面大7.两对: 两对就看谁的对

zoj 3818 Pretty Poem (模拟)

ZOJ Problem Set - 3818 Pretty Poem Time Limit: 2 Seconds      Memory Limit: 65536 KB Poetry is a form of literature that uses aesthetic and rhythmic qualities of language. There are many famous poets in the contemporary era. It is said that a few ACM

ZOJ 3818 Pretty Poem (暴力模拟 string(substr))

Pretty Poem Time Limit: 2 Seconds      Memory Limit: 65536 KB Poetry is a form of literature that uses aesthetic and rhythmic qualities of language. There are many famous poets in the contemporary era. It is said that a few ACM-ICPC contestants can e

1006 Do the Untwist

考察编程基础知识,用到字符和数字相互转化等.形式是描述清楚明文和暗文的转化规则. 1 #include <stdio.h> 2 #include <string.h> 3 4 #define MAXLEN 71 5 6 int length; 7 8 void toCode(int code[],char text[]){ 9 int i; 10 for(i=0;i<length;i++){ 11 if(text[i] == '_') 12 code[i] = 0; 13 e

zoj 3314 CAPTCHA(纯模拟)

题目 有些人用深搜写的,当然我这弱弱的,只理解纯模拟... 纯模拟,第一次写了那么长的代码,我自己也是够坚韧不拔的,,,,必须留念啊!!! 注意,G包含C,E包含L,R包含P,(照图说O应该不包含C,但是不排除掉这种情况,就wa掉了,所以要排除O包含C的情况..) #include<stdio.h> #include<string.h> int n,m; char s2[330][330]; int vis[30]; void fun(){ //a if(vis[0]==0){ f

ZOJ 3326 An Awful Problem 模拟

只有在 Month 和 Day 都为素数的时候才能得到糖 那就模拟一遍时间即可. //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include <stdio.h> #include <iostream> #include <fstream> #include <cstring> #include <cmath> #include <sta

ZOJ 2954 Hanoi Tower(模拟啊 )

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1953 You all must know the puzzle named "The Towers of Hanoi". The puzzle has three pegs (peg 1, peg 2 and peg 3) and N disks of different radii. Initially all disks are located on

ZOJ 3700 Ever Dream(模拟)

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3700 Ever Dream Time Limit: 2 Seconds      Memory Limit: 65536 KB  "Ever Dream" played by Nightwish is my favorite metal music. The lyric (see Sample Input) of this song is much