<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    小明思考

    Just a software engineer
    posts - 124, comments - 36, trackbacks - 0, articles - 0
      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

         摘要: Java 控制臺中文問題  閱讀全文

    posted @ 2012-01-19 16:18 小明 閱讀(3716) | 評論 (1)編輯 收藏

    最近開發的一個通用網絡爬蟲平臺,主要是想滿足自己想從特定網站抓取大量內容的需求,有如下特點:

    1. 支持cookie/session,所以支持登錄論壇和網站
    2. 支持圖像識別,可以由人工識別或者機器識別
    3. 多線程下載,性能不錯
    4. 支持代理
    5. 支持HTTPS和證書驗證
    6. 支持可插拔腳本,對特別網站使用特別的腳本(javascript編寫)。
    7. 有Web界面,操作方便

    項目位置:http://code.google.com/p/ssnaker/
    下載:http://ssnaker.googlecode.com/files/snaker_1.00_b7.zip

    最新的版本也實現一個火車票刷票的功能(具體實現都放在engines/train.js)


    posted @ 2012-01-13 15:45 小明 閱讀(3237) | 評論 (1)編輯 收藏

    原題:
    http://community.topcoder.com/stat?c=problem_statement&pm=164&rd=50

    Class Name: Prerequisites

    Mathod Name: orderClasses

    Parameters: String[]

    Returns: String[]

     

    You are a student at a college with the most unbelievably complex prerequisite

    structure ever. To help you schedule your classes, you decided to put together

    a program that returns the order in which the classes should be taken. 

     

    Implement a class Prerequisites which contains a method orderClasses. The

    method takes a String[] that contains the classes you must take and returns a

    String[] of classes in the order the classes should be taken so that all

    prerequisites are met.

     

    String[] elements will be of the form (and TopCoder will ensure this):

    "CLASS: PRE1 PRE2 ..." where PRE1 and PRE2 are prerequisites of CLASS. CLASS,

    PRE1, PRE2, ... consist of a department name (3 or 4 capital letters, A-Z

    inclusive) followed by a class number (an integer between 100 and 999,

    inclusive). The department name should be immediately followed by the class

    number with no additional characters, numbers or spaces (i.e. MATH217). It is

    not necessary for a class to have prerequisites. In such a case, the colon is

    the last character in the String. 

     

    You can only take one class at a time, therefore, use the following rules to

    determine which class to take :

    1) Any prerequisite class(es) listed for a class must be taken before the class

    can be taken.

    2) If multiple classes can be taken at the same time, you take the one with the

    lowest number first, regardless of department.

    3) If multiple classes with the same number can be taken at the same time, you

    take the department name which comes first in alphabetical order. 

    4) If the inputted course schedule has errors, return a String[] of length 0.

    There is an error if it is impossible to return the classes in an order such

    that all prerequisites are met, or if a prerequisite is a course that does not

    have its own entry in the inputted String[].

     

    Examples of valid input Strings are:

    "CSE111: CSE110 MATH101"

    "CSE110:"

     

    Examples of invalid input Strings are:

    "CS117:" (department name must consist of 3 - 4 capital letters, inclusive)

    "cs117:" (department name must consist of 3 - 4 capital letters, inclusive)

    "CS9E11:" (department name must be letters only)

    "CSE110: " (no trailing spaces allowed)

    "CSE110: CSE101 " (no trailing spaces allowed)

    "MATH211: MAM2222" (class number to large)

    "MATH211: MAM22" (class number to small)

    "ENGIN517: MATH211" (department name to large)

     

    Here is the method signature (be sure your method is public):

    String[] orderClasses(String[] classSchedule);

     

    TopCoder will make sure classSchedule contains between 1 and 20 Strings,

    inclusive, all of the form above. The Strings will have between 1 and 50

    characters, inclusive. TopCoder will check that the syntax of the Strings are

    correct: The Strings will contain a valid class name, followed by a colon,

    possibly followed by a series of unique prerequisite classes separated by

    single spaces. Also, TopCoder will ensure that each class has at most one

    entry in the String[].

     

    Examples:

    If classSchedule={

    "CSE121: CSE110",

    "CSE110:",

    "MATH122:",

    }

    The method should return: {"CSE110","CSE121","MATH122"}

     

    If classSchedule={

    "ENGL111: ENGL110",

    "ENGL110: ENGL111"

    }

    The method should return: {}

     

    If classSchedule=[

    "ENGL111: ENGL110"

    }

    The method should return: {}

     

    If classSchedule={

    "CSE258: CSE244 CSE243 INTR100"

    "CSE221: CSE254 INTR100"

    "CSE254: CSE111 MATH210 INTR100"

    "CSE244: CSE243 MATH210 INTR100"

    "MATH210: INTR100"

    "CSE101: INTR100"

    "CSE111: INTR100"

    "ECE201: CSE111 INTR100"

    "ECE111: INTR100"

    "CSE243: CSE254"

    "INTR100:"

    }

    The method should return:

    {"INTR100","CSE101","CSE111","ECE111","ECE201","MATH210","CSE254","CSE221","CSE2

    43","CSE244","CSE258"}

     

     

    Definition

              

    Class:      Prerequisites

    Method:   orderClasses

    Parameters:     String[]

    Returns: String[]

    Method signature:   String[] orderClasses(String[] param0)

    (be sure your method is public)


    ------------------------------------------------------------我的解法如下----------------------------------------

    想法很簡單,這道題本質上是一道排序問題,我們只需要定義好排序的邏輯,然后應用快排就可以了。


    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;

    public class Prerequisites {
        
    private static final String[] EMPTY = {};
        Map
    <String,Klass> classes = new HashMap<String,Klass>();
        
        
    static class Klass implements Comparable<Klass>{
            String name;
            
    int number;
            String dept;
            List
    <Klass> pres = new ArrayList<Klass>();
            
    boolean exist = false;
            
            Klass(String name){
                
    this.name = name;
                
    int len = name.length();
                
    this.number = Integer.parseInt(name.substring(len-3));
                
    this.dept =name.substring(0,len-3);
            }
            
            
    private boolean isPre(Klass k){
                
    if(k==thisreturn false;
                
                
    for(Klass p:this.pres){
                    
    if(k == p || p.isPre(k)) return true;
                }
                
    return false;
            }

            @Override
            
    public int compareTo(Klass that) {
                
    boolean pre = this.isPre(that);
                
    boolean sub = that.isPre(this);
                
                
    if(pre && sub){
                    
    throw new RuntimeException("circle detected");
                }
                
    else if(pre){
                    
    return 1;
                }
                
    else if(sub){
                    
    return -1;
                }
                
    if(this.number!=that.number) return this.number-that.number;
                
    return this.dept.compareTo(that.dept);
            }
        }
        
        
    private Klass getClass(String name){
            Klass k 
    = classes.get(name);
            
    if(k==null){
                k 
    = new Klass(name);
                classes.put(name, k);
            }
            
    return k;
        }
        
        
    public String[] orderClasses(String[] classSchedule){
            classes.clear();
            //parse the input
            
    for(String s:classSchedule){
                
    int idx = s.indexOf(":");
                String name 
    = s.substring(0,idx);
                Klass k 
    = getClass(name);
                k.exist 
    = true;
                
    if(idx!=s.length()-1){
                    String[] pres 
    = s.substring(idx+1).split(" ");
                    
    for(String pre:pres){
                        
    if(pre.length()>0){
                            Klass p 
    = getClass(pre);
                            k.pres.add(p);
                        }
                    }
                }
            }
            
            Klass [] sortedClasses 
    =  (Klass[]) classes.values().toArray(new Klass[0]);
            
    for(Klass k:sortedClasses){
                
    if(!k.exist){
                    
    return EMPTY;
                }
            }
            
    try {
                Arrays.sort(sortedClasses);
            } 
    catch (Exception e) {
                
    return EMPTY;
            }
            String[] result 
    = new String[sortedClasses.length];
            
    int c = 0;
            
    for(Klass k:sortedClasses){
                result[c
    ++= k.name;
            }
            
    return result;
        }
    }


    posted @ 2011-10-25 13:28 小明 閱讀(1823) | 評論 (3)編輯 收藏

    Here is my some recommendations for java i18n .

    1.  The correct way to handle text-based resource files for localization

     Use java.util.ResourceBoundle to read resource from file.

    e.g.
     Local local = Local.CHINA;
     ResourceBundle rb = ResourceBundle.getBundle("test", local);
     String title = rb.getString("helloworld.title");
     System.out.println(title);

     //The program will read file: test_zh.properties
     # This locale is zh_CN
     # helloworld.title=中文1234
     and the file should use native2ascii program to convert (native2ascii.exe is in JDK)
     # This locale is zh_CN
     helloworld.title=\u4f60\u597d1234

     if you don't use native2ascii  to covert,you must covert it in the java program,like this:
     ResourceBundle rb = ResourceBundle.getBundle("test", Locale.CHINA);
         String title = rb.getString("helloworld.title");
        System.out.println(new String(title.getBytes("8859_1")));  //covert to os/jvm default charset

    2.       Locale driven date and time display
     
     Use java.text.DateFormat to format date string
    e.g.
     DateFormat df = DateFormat.getDateInstance(DateFormat.FULL,Locale.CHINA);
     String date = df.format(new Date());
        System.out.println(date);

     DateFormat df2 = DateFormat.getDateTimeInstance(DateFormat.DEFAULT,DateFormat.DEFAULT,Locale.CHINA);
     String datetime = df2.format(new Date());
        System.out.println(datetime);

    3.       JSP localization method.

    1) native method:
     use "Local local = request.getLocale();" to get the page accessor's local info
     then use ResourceBoundle to read local resource
     and page should use utf-8 charset
     
    e.g.
    <%@ page contentType="text/html; charset=utf-8" %>
    <%
    Local local = request.getLocale();
    ResourceBundle rb = ResourceBundle.getBundle("test", local);
    String title = rb.getString("helloworld.title");
    %>
    <html>
    <head>
    <title>test</title>
    </head>
    <body bgcolor="#ffffff">
    <h1><%=title%></h1>
    </body>
    </html>
    notice:put the  test_zh.properties into directionary WEB_INF/classes

    2)use jsp taglib to simplify the page

     the Jakarta i18n taglib is a good choice. http://jakarta.apache.org/taglibs/doc/i18n-doc/index.html
    e.g.
    <%@ page contentType="text/html; charset=utf-8"%>
    <%@ taglib uri="<i18n:bundle baseName="test" id="test" localeRef="userLocale"
                 scope="request"
                 changeResponseLocale="false"/>
    <html>
    <head>
    <title>test</title>
    </head>
    <body bgcolor="#ffffff">
    <h1><i18n:message key="helloworld.title" /></h1>
    </body>
    </html>

    3)use j2ee web framework(Struts) to simplify

     the Struts web framework supply i18n support
     Please refer:
    http://www.allapplabs.com/struts/struts_internationalization.htm

    posted @ 2005-12-19 17:26 小明 閱讀(1129) | 評論 (1)編輯 收藏


    java blog:  http://m.tkk7.com/sandy

    cpp blog:  http://www.cppblog.com/sandy

    歡迎參觀。

    posted @ 2005-12-06 10:08 小明 閱讀(457) | 評論 (0)編輯 收藏

    僅列出標題
    共5頁: 上一頁 1 2 3 4 5 
    主站蜘蛛池模板: 亚洲国产模特在线播放| 久久精品国产精品亚洲蜜月| 久久精品国产亚洲av麻豆图片| 亚欧免费无码aⅴ在线观看| 亚洲AV人无码激艳猛片| 一区二区在线免费观看| 亚洲国产精品自在在线观看| 人妻丰满熟妇无码区免费| 亚洲精品午夜久久久伊人| 国产精品69白浆在线观看免费| 亚洲人成电影院在线观看| 在人线av无码免费高潮喷水| 日韩亚洲国产综合高清| 国产无遮挡吃胸膜奶免费看视频| 国产精品无码亚洲精品2021| 亚洲国产精品综合久久一线| 中文在线观看永久免费| 久久精品国产亚洲AV麻豆不卡 | 青青操视频在线免费观看| 亚洲精品无码MV在线观看| 日本人成在线视频免费播放| 亚洲精品国产第1页| 女人张开腿给人桶免费视频| 污污免费在线观看| 国产亚洲综合一区柠檬导航| 亚洲一级毛片免费观看| 亚洲性色AV日韩在线观看| 亚洲美女在线国产| 日本免费一区二区三区| 亚洲熟女综合一区二区三区| www.91亚洲| 久久精品毛片免费观看| 亚洲AV无码资源在线观看| 亚洲一区精品无码| 动漫黄网站免费永久在线观看 | 亚洲欧洲在线观看| 波多野结衣久久高清免费| 嫩草在线视频www免费看| 91在线亚洲综合在线| 亚洲色成人网站WWW永久| 久久笫一福利免费导航|