說明:ASCII 碼的運用,Java 中將字元轉成整數後減 7 再轉回字元印出即可,Python 中使用 ord 及 chr 函數來轉換。
補充:ASCII 碼 https://zh.wikipedia.org/wiki/ASCII
Java 版
import java.util.Scanner;
public class A009 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
char [] cs = in.nextLine().toCharArray();
for (char c : cs) {
int t = c;
t = t - 7;
System.out.print((char) t);
}
System.out.println();
}
}
}
Python 版 (2022.07)cs = list(input())
for c in cs:
print(chr(ord(c) - 7), end='')
print()
沒有留言:
張貼留言