//\\__ hr1212 __//\\
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mi;
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define nl printf("\n");
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define f(i,a,b) for(i=a;i<b;i++)
#define rf(i,a,b) for(i=a;i>=b;i--)
#define clr(x,a) memset(x,a,sizeof(x))
#define MAX 1000100
#define MOD 1000000007
int n,m,a[30][30],mk[30],b[30];
char s[1000000][25];
vi v;
void dfs(int x){
int i;
mk[x]=1;
f(i,0,26){
if(a[x][i] && !mk[i] && b[i])
dfs(i);
}
v.pb(x);
}
int main(){
int r,k,i,c=0,x=0,y=0,j,t,l,z,x1=0,y1=0;
ll ans=0;string p;
n=0;
while(scanf("%s",s[n])!=EOF){
clr(a,0);
clr(mk,0);
clr(b,0);
v.clear();
f(i,0,strlen(s[n]))
b[s[n][i]-'A']=1;
n=1;
while(1){
scanf("%s",s[n]);
if(s[n][0]=='#')
break;
f(i,0,strlen(s[n]))
b[s[n][i]-'A']=1;
n++;
}
f(i,0,n-1){
f(j,0,min(strlen(s[i]),strlen(s[i+1]))){
x=s[i][j]-'A';y=s[i+1][j]-'A';
if(x!=y){
a[x][y]=1;
break;
}
}
}
f(i,0,26){
if(!mk[i] && b[i])
dfs(i);
}
f(i,0,26){
c=0;
if(b[i]){
f(j,0,v.size())
if(v[j]==i){
c=1;
break;
}
if(!c)
v.pb(i);
}
}
rf(i,v.size()-1,0)
printf("%c",char(v[i]+'A'));
nl;
n=0;
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mi;
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define nl printf("\n");
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define f(i,a,b) for(i=a;i<b;i++)
#define rf(i,a,b) for(i=a;i>=b;i--)
#define clr(x,a) memset(x,a,sizeof(x))
#define MAX 1000100
#define MOD 1000000007
int n,m,a[30][30],mk[30],b[30];
char s[1000000][25];
vi v;
void dfs(int x){
int i;
mk[x]=1;
f(i,0,26){
if(a[x][i] && !mk[i] && b[i])
dfs(i);
}
v.pb(x);
}
int main(){
int r,k,i,c=0,x=0,y=0,j,t,l,z,x1=0,y1=0;
ll ans=0;string p;
n=0;
while(scanf("%s",s[n])!=EOF){
clr(a,0);
clr(mk,0);
clr(b,0);
v.clear();
f(i,0,strlen(s[n]))
b[s[n][i]-'A']=1;
n=1;
while(1){
scanf("%s",s[n]);
if(s[n][0]=='#')
break;
f(i,0,strlen(s[n]))
b[s[n][i]-'A']=1;
n++;
}
f(i,0,n-1){
f(j,0,min(strlen(s[i]),strlen(s[i+1]))){
x=s[i][j]-'A';y=s[i+1][j]-'A';
if(x!=y){
a[x][y]=1;
break;
}
}
}
f(i,0,26){
if(!mk[i] && b[i])
dfs(i);
}
f(i,0,26){
c=0;
if(b[i]){
f(j,0,v.size())
if(v[j]==i){
c=1;
break;
}
if(!c)
v.pb(i);
}
}
rf(i,v.size()-1,0)
printf("%c",char(v[i]+'A'));
nl;
n=0;
}
return 0;
}
No comments:
Post a Comment