谜题描述:
http://www.pythonchallenge.com/pc/def/ocr.html
从一大堆乱码中找出可以理解的信息(字母)
Java解决方案:
public class Test {
public static void main(String[] args) throws Exception {
URL url = new URL("http://www.pythonchallenge.com"
+ "/pc/def/ocr.html");
BufferedReader reader = new BufferedReader(new
InputStreamReader(url.openStream()));
StringBuffer sb = new StringBuffer();
int i = reader.read();
while(i != -1)
{
if((i >= (int)'A' && i <= (int)'Z')
|| (i >= (int)'a' && i <= (int)'z'))
{
sb.append((char)i);
}
i = reader.read();
}
reader.close();
String source = sb.toString();
//页面源码中最后一个单词是below
System.out.println(
source.substring(source.indexOf("below") + 5)
);
}
}
附Python和Shell:
Python:
>>> text = """
<copy and paste>
"""
>>> import string
>>> for i in text:
if i in string.ascii_letters:
print i,
Shell:
$ curl
http://www.pythonchallenge.com/pc/def/ocr.html | grep -o [a-z]
版权所有 罗明