zoukankan      html  css  js  c++  java
  • codevs 1277 生活大爆炸 2012年CCC加拿大高中生信息学奥赛

     时间限制: 1 s
     空间限制: 128000 KB
     题目等级 : 白银 Silver
    题目描述 Description

    Sheldon and Leonard are physicists who are fixated on the BIG BANG theory. In order to exchange secret insights they have devised a code that encodes UPPERCASE words by shifting their letters forward.

    谢耳朵和莱纳德是研究BB理论的物理学家。要用暗号(大写字母)联系。


    Shifting a letter by S positions means to go forward S letters in the alphabet. For example, shifting B by S = 3 positions gives E. However, sometimes this makes us go past Z, the last letter of the alphabet. Whenever this happens we wrap around, treating A as the letter that follows Z. For example, shifting Z by S = 2 positions gives B.

    (读懂这段话是解题的关键,翻译了就没意义了)


    Sheldon and Leonard’s code depends on a parameter K and also varies depending on the position of each letter in the word. For the letter at position P, they use the shift value of S = 3P + K.

    他们有一个密钥K。第P个字母有S = 3P + K。


    For example, here is how ZOOM is encoded when K = 3. The first letter Z has a shift value of S = 3 × 1 + 3 = 6; it wraps around and becomes the letter F. The second letter, O, has S = 3 × 2 + 3 = 9 and becomes X. The last two letters become A and B. So Sheldon sends Leonard the secret message: FXAB
    Write a program for Leonard that will decode messages sent by Sheldon.

    输入描述 Input Description

    The input will be two lines. The first line will contain the positive integer K (K < 10), which is used to compute the shift value. The second line of input will be the word, which will be a sequence of uppercase characters of length at most 20.

    输入有两行。第一行一个正整数K(〈10)。第二行是最多20个大写字母组成的信。

    输出描述 Output Description

    The output will be the decoded word of uppercase letters.

    输入就是解密后的信。

    样例输入 Sample Input

    样例1:

    3

    FXAB

    样例2:

    5

    JTUSUKG

    样例输出 Sample Output

    样例1:

    ZOOM

    样例2:

    BIGBANG

    数据范围及提示 Data Size & Hint
     
    #include<algorithm>
    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<cmath>
    
    using namespace std;
    
    int main()
    {
        char b[25];
        int i,k,s;
        scanf("%d",&k);
        scanf("%s",b);
        for(i=0;b[i];i++)
        {
            s=3*(i+1)+k;
            if(b[i]-s<'A')
            {
                s-=b[i]-'A';
                b[i]='Z'+1;
            }
            printf("%c",b[i]-s);
        }
    }
    我们都在命运之湖上荡舟划桨,波浪起伏着而我们无法逃脱孤航。但是假使我们迷失了方向,波浪将指引我们穿越另一天的曙光。
  • 相关阅读:
    敏捷开发原则与实践(七)之接口隔离原则
    敏捷开发原则与实践(六)之依赖倒置原则
    敏捷开发原则与实践(五)之替换原则
    敏捷开发原则与实践(四)之开放-关闭原则
    敏捷开发原则与实践(三)之 单一职责原则
    敏捷开发原则与实践(二)
    ios 3DTouch基本使用教程
    ios 关于正则表达式
    ios 含有textfield的viewcontroller随键盘弹起而改变位置
    ios 图片库和相机选择图片界面修改为简体中文
  • 原文地址:https://www.cnblogs.com/ruojisun/p/6613732.html
Copyright © 2011-2022 走看看