andy6804tw
8/17/2016 - 7:45 AM

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=29581

import java.util.*;    
    
public class Main {    
    
    public static void main(String[] args) {    
        Scanner scn = new Scanner(System.in);    
        int n=Integer.parseInt(scn.nextLine()),j=0;  
        String s[]=new String[n],str="";  
        for(int i=0;i<n;i++){  
            s[i]=scn.nextLine();  
        }  
        str+=s[0];  
        for(int i=1;i<n;i++){  
            j=s[i].length();  
            while(true){  
                if(str.contains(s[i].substring(0, j))){  
                    str+=s[i].substring(j, s[i].length());  
                    break;  
                }  
                j--;  
            }  
        }  
        System.out.println(str);  
              
          
    }    
}