ZOJ Problem Set - 1006 Do the Untwist

本文介绍了一个名为DotheUntwist的算法实现,该算法通过一系列字符转换过程来解码特定形式的密文。文章展示了如何使用C语言进行编码,并详细解释了字符映射、密文解析及还原明文的过程。

开发板推荐:天空星STM32F407VET6开发板

超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印

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

开发板推荐:天空星STM32F407VET6开发板

超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值