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;
}