谜题描述:
http://www.pythonchallenge.com/pc/def/map.html
Java解决方案:
1 public class Test {
2 public static void main(String[] args) {
3 String a = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq "
+ "ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb "
+ "gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq "
+ "qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. "
+ "lmu ynnjw ml rfc spj.";
4 char[] ac = a.toCharArray();
5 int zi = (int)'z';
6 int ai = (int)'a';
7 for(int index=0; index<ac.length; index++)
8 {
9 int aci = (int)ac[index];
10 if(aci >= ai && aci <= zi)
11 {
12 int aci2 = (int)ac[index] + 2;
13
14 System.out.print((char)((aci2>zi)?(aci2%(zi+1)+ai):aci2));
15 }
16 else
17 {
18 System.out.print((char)aci);
19 }
20 }
21 }
22 }
附上Python和Shell解决方案:
Python:
1 >>> import string
2 >>> text = """g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr
3 amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q
4 ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb.
5 lmu ynnjw ml rfc spj."""
6 >>> table = string.maketrans(
7 string.ascii_lowercase,
8 string.ascii_lowercase[2:]+string.ascii_lowercase[:2])
Shell:
$ tr [a-z] [c-za-b]
版权所有 罗明