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

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

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

    精彩的人生

    好好工作,好好生活

    BlogJava 首頁 新隨筆 聯系 聚合 管理
      147 Posts :: 0 Stories :: 250 Comments :: 0 Trackbacks

    聲明:代碼是作者原創,請勿作商業用途
    轉載請注明出處

    A rare book collector recently discovered a book written in an unfamiliar language that used the same characters as the English language. The book contained a short index, but the ordering of the items in the index was different from what one would expect if the characters were ordered the same way as in the English alphabet. The collector tried to use the index to determine the ordering of characters (i.e., the collating sequence) of the strange alphabet, then gave up with frustration at the tedium of the task.

    You are to write a program to complete the collector's work. In particular, your program will take a set of strings that has been sorted according to a particular collating sequence and determine what that sequence is.

    Input

    The input consists of an ordered list of strings of uppercase letters, one string per line. Each string contains at most 20 characters. The end of the list is signalled by a line dio is the single character `#'. Not all letters are necessarily used, but the list will imply a complete ordering among those letters that are used.

    Output

    Your output should be a single line containing uppercase letters in the order that specifies the collating sequence used to produce the input data file.

    Sample Input

    XWY
    ZX
    ZXY
    ZXW
    YWWX
    #

    Sample Output

    XZYW


    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.ArrayList;

    public class Problem200 {

        
    /**
         * 
    @param args
         
    */

        
    public static void main(String[] args) {
            ArrayList al 
    = new ArrayList();        
            
            
    try {
                
    while(true){
                    BufferedReader cin 
    = new BufferedReader( new InputStreamReader( System.in ) );
                    String s 
    = cin.readLine();
                    
    if(s==null || s.length()<1)
                        
    continue;
                    
                    
    if(s.equals("#"))
                        
    break;
                    
                    
    if(s.length()>20){
                        System.out.println(
    "length more than 20!");
                        
    return;
                    }

                    
    if(!isUpper(s)){
                        System.out.println(
    "there are chars not in upper case!");
                        
    return;
                    }

                    al.add(s);
                }

            }
     catch (IOException e) {
                
    // TODO Auto-generated catch block
                e.printStackTrace();
            }

            
            
    if(al.size()<1){
                System.out.println(
    "NONE");
            }

            
            
    char[][] charArr = new char[al.size()][20];
            
    for(int i=0; i<al.size(); i++){
                charArr[i] 
    = al.get(i).toString().toCharArray();
            }

            
            sort(charArr);
        }


        
    private static void sort(char[][] charArr) {
            
    char[] result = new char[26];
            
    int index = 0;
            
            
    char ch;
            
    for(int i=0; i<charArr.length; i++){
                
    for(int j=0; j<charArr[i].length; j++){
                    ch 
    = charArr[i][j];
                    
    if(index==0){
                        result[index] 
    = ch;
                        index
    ++;
                    }
    else{
                        
    if(contains(ch, result, index)){
                            
    continue;
                        }
    else{
                            result[index] 
    = ch;
                            index
    ++;
                        }

                    }

                }

            }

            StringBuffer buffer 
    = new StringBuffer();
            
    for(int i=0; i<index; i++){
                buffer.append(result[i]);
            }

            
            System.out.println(buffer.toString());
        }


        
    private static boolean contains(char ch, char[] result, int index) {
            
    boolean flag=false;
            
    for(int i=0; i<index; i++){
                
    if(result[i]==ch){
                    flag
    =true;
                    
    break;
                }

            }

            
    return flag;
        }


        
    private static boolean isUpper(String s) {
            
    boolean result=true;
            
    for(int i=0; i<s.length(); i++){
                
    if(s.charAt(i)>='A' && s.charAt(i)<='Z')
                    
    continue;
                
    else{
                    result
    =false;
                    
    break;
                }

            }

            
    return result;
        }


    }


    歡迎討論
    posted on 2005-12-07 15:20 hopeshared 閱讀(852) 評論(3)  編輯  收藏 所屬分類: Google Code Jam

    Feedback

    # re: Rare Order 2006-09-01 06:44 Guest
    Have you ever tested your solution?  回復  更多評論
      

    # re: Rare Order[未登錄] 2007-07-22 00:13 Kelvin
    請問它是 怎么排序的,它的順序是怎么決定的  回復  更多評論
      

    # re: Rare Order[未登錄] 2014-10-19 04:35 123
    @Guest
    Wrong at all!!!!  回復  更多評論
      


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 青娱分类视频精品免费2| 国产成人精品高清免费| 日本最新免费网站| 国产又大又长又粗又硬的免费视频 | 一级一黄在线观看视频免费| 最近2019中文字幕免费大全5| 麻豆精品国产免费观看| 亚洲成在人天堂一区二区| 亚洲国产精品无码观看久久| 日韩午夜理论免费TV影院| 亚洲国产aⅴ综合网| 亚洲91精品麻豆国产系列在线| 99精品全国免费观看视频..| 国产男女猛烈无遮挡免费视频网站 | 四虎国产精品免费永久在线| 亚洲成色在线综合网站| 特级毛片在线大全免费播放| 女人18毛片水真多免费看| 亚洲美女自拍视频| 在线观看特色大片免费网站 | 伊人久久综在合线亚洲91| 欧美日韩亚洲精品| 在线视频观看免费视频18| 久久精品国产亚洲AV无码娇色| 国产在线观看无码免费视频| 亚洲国产成人久久综合区| 中国一级特黄高清免费的大片中国一级黄色片 | 国产精品亚洲四区在线观看| 免费女人高潮流视频在线观看| 亚洲国产美女精品久久| 最近中文字幕mv免费高清视频8 | 农村寡妇一级毛片免费看视频| 免费视频淫片aa毛片| 国产精品无码永久免费888| 亚洲 小说区 图片区 都市| 国产产在线精品亚洲AAVV| 四虎永久免费地址在线观看| 伊人久久大香线蕉免费视频| 亚洲中文字幕一二三四区| 国语成本人片免费av无码| 亚洲精品无码一区二区|