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; }
最後更新:2017-04-03 12:55:26
上一篇:
Oracle EXTRACT (datetime)
下一篇:
C# WinForm中PreviewKeyDown、KeyDown、KeyPress、KeyUp區別與聯係
數據蔣堂 | 迭代聚合語法
jquery設計思想書目錄
svnserve:error while loading shared libraries: libaprutil-1.so.0: cannot open shared object file: No such file or directory
阿裏分布式數據庫服務實踐
大數據阿裏雲產品的簡單介紹理解
作為開發者,你不應該害怕的 8 件事
JS操作剪貼板
交通數據分析幫你避開99%的酒駕司機
PostgreSQL 10.0 preview 功能增強 - CLOG oldest XID跟蹤
優酷盜播引版權方圍攻 視頻大佬陷孤軍奮戰困局