zoj 1006 do the untwist
生活随笔
收集整理的這篇文章主要介紹了
zoj 1006 do the untwist
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目見zoj 1006 或poj 1317?
簡單的解密算法,直接套用題目中公式即可。
?
/* zoj 1006 Do the Untwist */ #include <stdio.h> #include <string.h>#define MAXLEN 80 #define MAGICNUM 28char num2Char(int n); int char2Num(char c); int main(void) {int key;char ciphertext[MAXLEN],plaintext[MAXLEN];int ciphercode[MAXLEN],plaincode[MAXLEN];int slen,i;while(scanf("%d", &key) == 1 && key != 0){scanf("%s", ciphertext);slen = strlen(ciphertext);for(i = 0; i < slen; i++){ciphercode[i] = char2Num(ciphertext[i]);plaincode[(key * i) % slen] = (i+ciphercode[i])%MAGICNUM;}for(i = 0; i < slen; i++)plaintext[i] = num2Char(plaincode[i]);plaintext[slen] = '\0';printf("%s\n",plaintext);}return 0; } int char2Num(char c) {if( c == '_')return 0;else if( c == '.')return 27;elsereturn c - 'a' + 1; } char num2Char(int n) {if(n == 0)return '_';else if(n == 27)return '.';elsereturn 'a' + n - 1; }總結
以上是生活随笔為你收集整理的zoj 1006 do the untwist的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Modbus通信协议之CRC16冗余循环
- 下一篇: 杨辉三角——数组解决