2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest
H. Delete Them
题意: 给你几个字符串,和一组数,要求这组数的字符串能由同一个图案匹配,并且这组数外的其他字符串没有能与其匹配。
题解: 可知,这组数的字符串同字符串长度,即可匹配,搞出来的匹配字符串,再去寻这组数外的其他字符串有没有能与其匹配。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
using namespace std;
const int N = 100+10;
typedef long long LL;
const int INF=0x3f3f3f3f;
char s[N][N];
char ans[N];
int a[N];
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i = 1; i <= n; i++)
scanf("%s",s[i]);
for(int i = 0; i < m; i++)
scanf("%d",&a[i]);
int len = strlen(s[a[0]]);
int i,j;
for(i = 1; i < m; i++)
{
int x = strlen(s[a[i]]);
if(x != len)
break;
}
if(i != m)
{
puts("No");
return 0;
}
int k = 0;
for(i = 0; i < len; i++)
{
char c = s[a[0]][i];
for(j = 1; j < m; j++)
{
char x = s[a[j]][i];
if(x != c)
break;
}
if(j != m)
ans[k++] = '?';
else
ans[k++] = c;
}
ans[k] = '\0';
int num = 0;
for(i = 1; i <= n; i++)
{
if(i == a[num])
num++;
else
{
if(strlen(s[i]) != len)
continue;
for(j = 0; j < k; j++)
{
if(s[i][j] != ans[j] && ans[j] != '?')
break;
}
if(j == k)
break;
}
}
if(i != n+1)
puts("No");
else
{
puts("Yes");
printf("%s\n",ans);
}
return 0;
}