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

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

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

    精彩的人生

    好好工作,好好生活

    BlogJava 首頁(yè) 新隨筆 聯(lián)系 聚合 管理
      147 Posts :: 0 Stories :: 250 Comments :: 0 Trackbacks

    聲明:代碼是作者原創(chuàng),請(qǐng)勿作商業(yè)用途
    轉(zhuǎn)載請(qǐng)注明出處

    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) 評(píng)論(3)  編輯  收藏 所屬分類(lèi): Google Code Jam

    Feedback

    # re: Rare Order 2006-09-01 06:44 Guest
    Have you ever tested your solution?  回復(fù)  更多評(píng)論
      

    # re: Rare Order[未登錄](méi) 2007-07-22 00:13 Kelvin
    請(qǐng)問(wèn)它是 怎么排序的,它的順序是怎么決定的  回復(fù)  更多評(píng)論
      

    # re: Rare Order[未登錄](méi) 2014-10-19 04:35 123
    @Guest
    Wrong at all!!!!  回復(fù)  更多評(píng)論
      


    只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
    相關(guān)文章:
     
    主站蜘蛛池模板: 丁香花在线观看免费观看图片| 亚洲女人影院想要爱| 国产精品亚洲专区无码唯爱网| 成人免费一区二区无码视频| 亚洲人成网站18禁止久久影院| 无码人妻精品中文字幕免费 | 91国内免费在线视频| 亚洲另类激情综合偷自拍图| 97人妻精品全国免费视频| 日韩a毛片免费观看| 日韩高清免费在线观看| 亚洲精品国产第一综合99久久 | 精品一区二区三区免费观看| 亚洲色精品vr一区二区三区| 大地资源中文在线观看免费版| 亚洲AV中文无码字幕色三| 免费毛片a线观看| 久久久亚洲欧洲日产国码农村| 91高清免费国产自产拍2021| 亚洲国产视频网站| 好男人视频在线观看免费看片| 美国免费高清一级毛片| 老司机亚洲精品影视www| 久久久国产精品福利免费| 亚洲黄色在线观看| 好爽又高潮了毛片免费下载| 成人久久久观看免费毛片| 亚洲国产精品成人精品无码区| 免费观看激色视频网站(性色)| 亚洲性色精品一区二区在线| 久久午夜无码免费| 久久久久精品国产亚洲AV无码| 在线观看免费为成年视频| 一区视频免费观看| 337p日本欧洲亚洲大胆精品555588 | 在线免费视频你懂的| 亚洲色av性色在线观无码| 宅男666在线永久免费观看| 国产精品视频全国免费观看| 亚洲熟妇无码久久精品| 亚洲AV日韩精品一区二区三区|