竹園論壇

標題: Q458 - The Decoder [打印本頁]

作者: HSCHE    時間: 2014-4-29 08:11
標題: Q458 - The Decoder
在密碼學裡面有一種很簡單的加密方式,就是把明碼的每個字元加上某一個整數K而得到密碼的字元(明碼及密碼字元一定都在ASCII碼中可列印的範圍內)。例如若K=2,那麼apple經過加密後就變成crrng了。解密則是反過來做。這個問題是給你一個密碼字串,請你依照上述的解密方式輸出明碼。
至於在本任務中K到底是多少,請自行參照Sample Input及Sample Output推出來吧!相當簡單的。
Input
每筆測試資料一列。每列有1個字串,就是需要解密的明碼。
Output
對每一測試資料,請輸出解密後的密碼。
Sample Input
1JKJ'pz'{ol'{yhklthyr'vm'{ol'Jvu{yvs'Kh{h'Jvywvyh{pvu51PIT'pz'h'{yhklthyr'vm'{ol'Pu{lyuh{pvuhs'I|zpulzz'Thjopul'Jvywvyh{pvu51KLJ'pz'{ol'{yhklthyr'vm'{ol'Kpnp{hs'Lx|pwtlu{'Jvywvyh{pvu5
Sample Output
*CDC is the trademark of the Control Data Corporation.*IBM is a trademark of the International Business Machine Corporation.*DEC is the trademark of the Digital Equipment Corporation.

在此附上題目連結UVA:http://uva.onlinejudge.org/external/4/458.html LUCKY CAT: http://luckycat.kshs.kh.edu.tw/homework/q458.htm

解題感想:這題所使用的讀入關鍵字為getline,這是一個相當好用的關鍵字,他可以一次讀一行,還有這題的ASCII碼差"-7"
AC CODE:
#include<iostream>
  • #include<cstdio>
  • #include<cstring>
  • using namespace std;
  • int main()
  • {
  •         int t;
  •         //char w[10000];
  •         string w;
  •         while(getline(cin,w))
  •         {
  •                 for(int i=0;i<w.length();i++)
  •                         w[i]+=('*'-'1');
  •                 cout<<w<<"\n";
  •         }
  • }










  • 歡迎光臨 竹園論壇 (http://forum.tfcis.org/) Powered by Discuz! X3.2