poj-1317

来源:互联网 发布:ubuntu界面太小 编辑:程序博客网 时间:2024/04/30 20:18
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define maxl 75int key;char cipher_text[maxl];char plain_text[maxl];bool is_letter(char ch){    return ch <= 'z' && ch >= 'a';}int get_code(char ch){    if (is_letter(ch))        return ch - 'a' + 1;    if (ch == '_')        return 0;    if (ch == '.')        return 27;    return -1;}char get_text(int a){    if (a <= 26 && a >= 1)        return a + 'a' - 1;    if (a == 0)        return '_';    if (a == 27)        return '.';    return -1;}int unify(int a, int w){    return (a % w + w) % w;}int main(){    //freopen("t.txt", "r", stdin);    while (scanf("%d", &key), key)    {        scanf("%s", cipher_text);        int len = strlen(cipher_text);        for (int i = 0; i < len; i++)            plain_text[unify(key * i, len)] = get_text(unify(get_code(cipher_text[i]) + i, 28));        plain_text[len] = 0;        puts(plain_text);    }    return 0;}


想不通为啥 A = (B-i)%C,  (0<=A <C, 0 <= B < C)

逆运算就是 B = (A + i+ C)%C?,是因为 0<=B<C?

0 0
原创粉丝点击