# Zero judge a009.解碼器 ## 解題思路 ##### 1不能直接用cin>>input,因為會因空白斷行 ##### 2.輸入是1,輸出是*,用ASCIIcode計算後 49-k=42 ,得k=7 ##### 3.input每個'字'都需要-k,才能解密 #### 4.解密後直接輸出就豪 ```c++= #include "pch.h" #include <iostream> #include<string> using namespace std; int main() { string encrypt; while (getline(cin, encrypt))//讀入整行 { int k = 7; /* 在encrypt的範圍內,跑完for迴圈後,char decrypt會存放結果,類型最後是char for (int i = 0; i < encrypt.length(); i++) { char decrypt = encrypt[i];//取出字串中的第i字元 decrypt -= k; cout << decrypt; } 範圍型的for迴圈 每次跑for迴圈的時候會自動從encrypt取出一個字元並存在decrypt中,所以直接-就好 */ for (char decrypt : encrypt) { decrypt -= k;//secrypt=decrypt-k cout << decrypt; } } } ``` ###### tags: `Zero judge`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up