题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3603
代码:
#include <iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
int T;
char str1[15],str2[15];
int n;
char temp;
scanf("%d",&T);
while(T--)
{
bool flag[30];
bool flagg[30];
memset(flag,true,sizeof(flag));
scanf("%d",&n);
scanf("%s",str1);
for(int i=2;i<=n;i++)
{
scanf("%s",str2);
memset(flagg,true,sizeof(flagg));
for(int k=0;k<12;k++)
{
if(flag[k])
{
for(int j=0;j<12;j++)
if(str1[k]!=str2[j] && flagg[j] )
{
flag[k]=false;
}
else
if(str1[k]==str2[j] && flagg[j])
{
flag[k]=true;
flagg[j]=false;
break;
}
}
}
}
for(int i=0;i<12;i++)
for(int j=i+1;j<12;j++)
{
if(flag[i] &&flag[j])
{
if(str1[i]>str1[j])
{
temp=str1[j];
str1[j]=str1[i];
str1[i]=temp;
}
}
}
for(int i=0;i<12;i++)
if(flag[i])
printf("%c",str1[i]);
printf("\n");
}
return 0;
}