declare scores[], n
read input to n
for i from 0 to n - 1 :
read input to scores[i]
if scores[i] > 0 :
set scores[i] to 0
for i from n - 1 to 0 :
output scores[i]
#include <iostream>
using namespace std ;
int main() {
int n, scores[10005] ;
cin >> n ;
for (int i = 0; i < n; i++) {
cin >> scores[i] ;
if (scores[i] > 0) {
scores[i] = 0 ;
}
}
for (int i = n - 1; i >= 0; i--) {
cout << scores[i] << "\n" ;
}
}
plaintext: sprout
key: abcdef
cyphertext: sqtryy
根據觀察會發現,在同一行中從上往下看,字母會是正常的英文字母順序,直到遇到 z 之後再接 a。
所以其實不用把整個表記錄下來,只需要用推算的就好!
比如說現在是明文的字母是 s,而金鑰的字母是 j。
我們知道 j 是從
而為了方便我們做紀錄,我們可能會想要開一個陣列,每個索引值代表不同的字母,比如說 a 的資訊就存在索引值為
所以知道加密過後的字母是第幾個字母是至關重要的。
實際上寫成 code 的話,大概會是類似:
(int)(('s' - 'a' + 'j' - 'a') % 26) // integer 形式,也就是從 0 開始數的第幾個字母
declare text[], key[], count[]
initialize count[] to 0
read input to text and key
for i from 0 to strlen(text) :
declare cypher_num
set cypher_num to get_cypher_num(text[i], key[i])
count[cypher_num] += 1
for i from 0 to 25 :
output count[i]
#include <iostream>
using namespace std ;
int main() {
char text[1005], key[1005] ;
int count[26] = {0} ;
cin >> text >> key ;
int text_len = strlen(text) ;
for (int i = 0; i < text_len; i++) {
count[(int)(text[i] - 'a' + key[i] - 'a') % 26]++ ;
}
for (int i = 0; i < 26; i++) {
cout << count[i] ;
if (i < 25) cout << " " ;
}
return 0 ;
}