Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Author : unlucky_13
- Problem_link : http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=156&problem=136&mosmsg=Submission+received+with+ID+11792907
- Category :
- Algorithm_Used :
- */
- #include<cstdio>
- #include<sstream>
- #include<cstdlib>
- #include<cctype>
- #include<cmath>
- #include<algorithm>
- #include<set>
- #include<queue>
- #include<stack>
- #include<list>
- #include<iostream>
- #include<fstream>
- #include<numeric>
- #include<string>
- #include<vector>
- #include<cstring>
- #include<map>
- #include<iterator>
- #define LL long long int
- //const long long int inf = 2147483647 ;
- //const int minx=;
- //const int maxn=;
- using namespace std;
- int M[50][50] ;
- vector<char>ans ;
- int taken[100] ;
- void DFS(int u)
- {
- for(int i=0;i<31;i++)
- {
- if(M[u][i]==1 && taken[i]==0) DFS(i) ;
- }
- ans.push_back(u+'A') ;
- taken[u]=1 ;
- return ;
- }
- int main() {
- freopen("C:\\Users\\Mazhar\\Desktop\\Text_Files\\in.txt", "r", stdin);
- char in[5000][25] ;
- int I ;
- while(scanf("%s",in[0])!=EOF)
- {
- memset(M,0,sizeof(M)) ;
- ans.clear() ;
- for(int i=0;i<31;i++) taken[i]=1 ;
- I=1 ;
- while(1)
- {
- scanf("%s",in[I]) ;
- if(in[I][0]=='#') break ;
- else
- {
- for(int j=0;j<strlen(in[I]);j++) taken[in[I][j]-'A']=0 ;
- I++ ;
- }
- }
- for(int i=0;i<I-1;i++){
- for(int j=i+1;j<I;j++){
- int k = 0 ;
- while(in[i][k]==in[j][k]) k++ ;
- if(in[i][j]!='\0' ||in[j][k]!='\0')
- {
- M[in[j][k]-'A'][in[i][k]-'A']=1 ;
- }
- }
- }
- for(int i=0;i<31;i++){
- if(taken[i]==0) DFS(i) ;
- }
- for(int i=0;i<ans.size();i++) cout<<ans[i] ;
- cout<<endl ;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment