WIKIOI-1277 生活大爆炸

简介:

题目描述 Description

Sheldon and Leonard are physicists who are ?xated 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 ?rst 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 ?rst 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

 

 

#include<stdio.h>
#include<string.h>
char a[27]={'0','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char b[2000];
int main()
{
    int i,j,n,m,k,s,flag,x;
    scanf("%d",&n);
    getchar();
    scanf("%s",b);
    m=strlen(b); 
    k=0;
    for(i=0;i<m;i++)
    {
       for(j=1;j<=26;j++)
       {
         if(a[j]==b[i])
         {
           flag=j;
           break;
         }
       }
       s=3*(i+1)+n;
       x=0;
       if(flag-s>0)
       j=flag-s;
       else
       {
           j=flag-s+26;
       }
       b[k++]=a[j];
    }
    for(i=0;i<k;i++)
    printf("%c",b[i]);
    puts("");
    return 0;
}


相关文章
|
机器学习/深度学习 传感器 算法
【DOA估计】基于music和CAPON算法DOA估计附Matlab代码
【DOA估计】基于music和CAPON算法DOA估计附Matlab代码
|
机器学习/深度学习 传感器 数据采集
【DOA估计】基于esprit算法实现线性调频信号DOA估计附matlab代码
【DOA估计】基于esprit算法实现线性调频信号DOA估计附matlab代码
|
机器学习/深度学习 传感器 算法
【DOA估计】基于MUSIC和CAPON算法DOA估计附Matlab代码
【DOA估计】基于MUSIC和CAPON算法DOA估计附Matlab代码
|
机器学习/深度学习 计算机视觉
【CV】梯度消失和梯度爆炸
介绍一下梯度消失和梯度爆炸
【CV】梯度消失和梯度爆炸
|
人工智能 机器学习/深度学习
wikioi 1098 均分纸牌
wikioi 1098 均分纸牌 2002年NOIP全国联赛提高组题目描述 Description 有 N 堆纸牌,编号分别为 1,2,…, N。每堆上有若干张, 但纸牌总数必为 N 的倍数。可以在任一堆上取若于张纸牌,然后移动。
887 0
|
人工智能 算法 Windows
wikioi 1688 求逆序对
/*=========================================================== wikioi 1688 求逆序对 时间限制: 1 s 空间限制: 128000 KB 题目描述 Description 给定一个序列a1,a2,…,an,如果存在iaj,那么我们称之为逆序对,求逆序对的数目.
1115 0