WOJ1029Ascend

29. Ascend

时间限制: 1000 ms
内存限制: 524288 KiB
输入 / 输出: stdio
难度: 3 / 5

提交代码

Cryptography deals with methods of secret communication that transform a message (the plaintext) into a disguised form (the ciphertext) 
so that no one seeing the ciphertext will be able to figure out the plaintext except the intended recipient. Transforming the plaintext to 
the ciphertext is encryption; transforming the ciphertext to the plaintext is decryption. 
Ascend is a simple encryption method that only deal with capital letters. It shifts the i-th letter in a word forwards by i steps in alphabet, 
and you may assume the alphabet is circular in that letter Z will follow the letter A. 
For example: I ascend WHU to XJX. The process is as follow: 
1. I shift the first letter W forwards 1 step to X. 
2. I shift the second letter H forwards 2 steps to J. 
3. I shift the third letter U forwards 3 steps to X. 
Your task is to write a program that can decrypt the messages which are ascended. 

输入格式

The input file contains one or more test cases, followed by a line containing only the symbol $ that signals the end of the file. Each test case is on a line by itself and consists of an ascended message containing at least one and at most 100 capital letters. You may assume the message dose not contain other characters.

输出格式

For each test case, output the decrypted message on a line by itself.

样例输入

XJX
BEPMHVJ
$

样例输出

WHU
ACMICPC

来源

WHUCPC04 Final Round

 

C代码:

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char s[1000];
    while (gets(s) && s[0] != '$') {
        int i = 0;
        while (s[i] >= 'A'&&s[i] <= 'Z') {
            s[i] -= i + 1;
            while (s[i] < 'A') s[i] += 26;
            printf("%c", s[i]);
            i++;
        }
        printf("\n");
        int j = 0;
        while (s[i] >= 'A'&&s[i] <= 'Z') {
            s[i] = 0;
            j++;
        }
    }

    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值