高層タワー [MISSION LEVEL: B]
1 #include <bits/stdc++.h> 2 #define _for(i,a,b) for(int i = (a);i < (b);i ++) 3 #define pb push_back 4 using namespace std; 5 6 int main() 7 { 8 int n; 9 while(~scanf("%d",&n)) 10 { 11 string s[n],rnt; 12 _for(i,0,n) 13 { 14 cin >> s[i]; 15 } 16 rnt += s[0]; 17 _for(i,1,n) 18 { 19 int j = 0; 20 for(;j < rnt.size();j ++) 21 if(rnt[j]==s[i][0]) 22 { 23 int flag = 0; 24 for(int k = 0;k < s[i].size() && j+k < rnt.size();k ++) 25 { 26 if(s[i][k]!=rnt[j+k]) 27 { 28 flag = 1; 29 break; 30 } 31 } 32 if(!flag&&s[i].size()>=rnt.size()-j) 33 { 34 break; 35 } 36 } 37 string tmp; 38 _for(k,rnt.size()-j,s[i].size()) 39 tmp += s[i][k]; 40 rnt += tmp; 41 } 42 cout << rnt << endl; 43 } 44 return 0; 45 }