ZOJ Problem Set - 1006 Do the Untwist

ZOJ Problem Set - 1006
Do the Untwist

#include<stdio.h>
#include<string.h>

char mid[] = "_abcdefghijklmnopqrstuvwxyz.";
char ciphertext[75] ={ 0 };
char plaintext[75] = { 0 };
int  ciphercode[75] = { 0 };
int  plaincode[75] = { 0 };

int main(void)
{
    int k, n, i, j;
    while (scanf("%d", &k) == 1 && k)
    {
        scanf("%s", ciphertext);
        n = strlen(ciphertext);
        for (i = 0; i < n; ++i)
            for ( j = 0; j < 28; ++j)
                if (ciphertext[i] == mid[j])
                  {   ciphercode[i] = j; break;     }
        for (i = 0; i < n; ++i)
            plaincode[k*i%n] = (ciphercode[i] + i) % 28;
        for (i = 0; i < n; ++i)
            plaintext[i] = mid[plaincode[i]];
        plaintext[i] = '\0';
        puts(plaintext);
    }
    return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章