謎題描述: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
           
          主站蜘蛛池模板: 武隆县| 广安市| 定南县| 西乌珠穆沁旗| 建湖县| 南充市| 新绛县| 江华| 石楼县| 靖宇县| 达拉特旗| 平陆县| 二连浩特市| 广东省| 铁岭市| 乐东| 荥经县| 封开县| 诏安县| 长宁县| 葵青区| 梁河县| 娄烦县| 济阳县| 建德市| 铁岭市| 烟台市| 孙吴县| 清涧县| 济源市| 乌兰县| 荣成市| 泾源县| 成武县| 大理市| 穆棱市| 金秀| 兴海县| 景宁| 星座| 靖西县|