謎題描述: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]


          版權所有 羅明
          posted on 2008-05-07 16:11 羅明 閱讀(1507) 評論(28)  編輯  收藏 所屬分類: JavaStudyPython
          Comments
           
          主站蜘蛛池模板: 文成县| 临漳县| 西华县| 天台县| 迁西县| 林甸县| 体育| 昌图县| 克拉玛依市| 电白县| 慈溪市| 永康市| 商河县| 青冈县| 武川县| 玉田县| 和静县| 措美县| 安顺市| 长沙市| 光泽县| 克拉玛依市| 台东县| 辰溪县| 崇义县| 二连浩特市| 阜城县| 高雄市| 康马县| 宿州市| 清涧县| 二连浩特市| 甘洛县| 甘南县| 金塔县| 平顺县| 泗阳县| 稻城县| 师宗县| 彩票| 咸阳市|