CF730H:Delete Them(字符串处理)

解决一个编程问题,通过创建一个模式来精确匹配指定的文件列表并避免误删其他文件。任务涉及分析多个字符串,找出共同特征,并构建一个通用模式。

H. Delete Them
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

Polycarp is a beginner programmer. He is studying how to use a command line.

Polycarp faced the following problem. There are n files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the pattern and all other files shouldn't match the pattern.

Polycarp doesn't know about an asterisk '*', the only special character he knows is a question mark '?' which matches any single character. All other characters in the pattern match themselves only.

Formally, a pattern matches a filename if and only if they have equal lengths and all characters in the corresponding positions are equal except when the character in the pattern is '?', in which case the corresponding filename character does not matter.

For example, the filename pattern "a?ba?":

  • matches filenames "aabaa", "abba.", "a.ba9" and "a.ba.";
  • does not match filenames "aaba", "abaab", "aabaaa" and "aabaa.".

Help Polycarp find a pattern which matches files to be deleted and only them or report if there is no such pattern.

Input

The first line of the input contains two integers n and m (1 ≤ m ≤ n ≤ 100) — the total number of files and the number of files to be deleted.

The following n lines contain filenames, single filename per line. All filenames are non-empty strings containing only lowercase English letters, digits and dots ('.'). The length of each filename doesn't exceed 100. It is guaranteed that all filenames are distinct.

The last line of the input contains m distinct integer numbers in ascending order a1, a2, ..., am (1 ≤ ai ≤ n) — indices of files to be deleted. All files are indexed from 1 to n in order of their appearance in the input.

Output

If the required pattern exists, print "Yes" in the first line of the output. The second line should contain the required pattern. If there are multiple solutions, print any of them.

If the required pattern doesn't exist, print the only line containing "No".

Examples
input
3 2
ab
ac
cd
1 2
output
Yes
a?
input
5 3
test
tezt
test.
.est
tes.
1 4 5
output
Yes
?es?
input
4 4
a
b
c
dd
1 2 3 4
output
No
input
6 3
.svn
.git
....
...
..
.
1 2 3
output
Yes
.???

题意:给N个字符串,要指定删除其中的M条,要求输出一条匹配字符串:将这M条字串的公有字符保留,其余换成'?',且该匹配字符不能误杀其他不能删除的字符串。若不存在这样的匹配字符串输出No。

# include <stdio.h>
# include <string.h>
char a[102][101];
int b[101], slen[101];
int main()
{
    int n, m;
    while(~scanf("%d%d",&n,&m))
    {
        memset(a[101], 0, sizeof(a[101]));
        int len = 0, flag = 0, num=0, val=0;
        for(int i=1; i<=n; ++i)
        {
            scanf("%s",a[i]);
            slen[i] = strlen(a[i]);
        }
        for(int i=0; i<m; ++i)
        {
            scanf("%d",&b[i]);
            if(flag)
                continue;
            if(!len)
                len = slen[b[i]];
            else
                flag = (len != slen[b[i]]);//判断这M条字符串长度是否相等。
        }
        if(flag)
        {
            puts("No");
            continue;
        }
        for(int i=0; i<len; ++i)
        {
            char c = a[b[0]][i];
            int flag2 = 0;
            for(int j=1; j<m; ++j)
                if(a[b[j]][i] != c)
                {
                    ++num;
                    flag2 = 1;
                    break;
                }
            a[101][i] = flag2?'?':c;
        }
        val = len - num;//记录非'?'的字符个数。
        num = 0;
        for(int i=1; i<=n; ++i)//判断会不会误杀其他字符串。
            if(slen[i] == len)
            {
                int tmp = 0;
                for(int j=0; j<len; ++j)
                    if(a[101][j] != '?' && a[101][j] == a[i][j])
                        ++tmp;
                if(tmp == val)
                    ++num;
            }
        if(num > m)
        {
            puts("No");
            continue;
        }
        printf("Yes\n%s\n",a[101]);
    }
    return 0;
}


源码来自:https://pan.quark.cn/s/41b9d28f0d6d 在信息技术领域中,jQuery作为一个广受欢迎的JavaScript框架,显著简化了诸多操作,包括对HTML文档的遍历、事件的管理、动画的设计以及Ajax通信等。 本篇文档将深入阐释如何运用jQuery达成一个图片自动播放的功能,这种效果常用于网站的轮播展示或幻灯片演示,有助于优化用户与页面的互动,使网页呈现更加动态的视觉体验。 为了有效实施这一功能,首先需掌握jQuery的核心操作。 通过$符号作为接口,jQuery能够迅速选取DOM组件,例如$("#id")用于选取具有特定ID的元素,而$(".class")则能选取所有应用了某类class的元素。 在选定元素之后,可以执行多种行为,诸如事件监听、样式的变更、内容的更新以及动画的制作等。 关于“一个基于jQuery的图片自动播放功能”,首要任务是准备一组图片素材,这些素材将被整合至一个容器元素之中。 例如,可以构建一个div元素,将其宽度设定为单张图片的尺寸,再借助CSS实现溢出内容的隐藏,从而构建出水平滚动的初始框架。 ```html<div id="slider"> <img src="image1.jpg" alt="Image 1"> <img src="image2.jpg" alt="Image 2"> <!-- 更多图片内容... --></div>```接着,需要编写jQuery脚本以实现图片的自动切换。 这通常涉及到定时器的运用,以设定周期性间隔自动更换当前显示的图片。 通过使用`.fadeOut()`和`.fadeIn()`方法,能够实现图片间的平滑过渡,增强视觉效果。 ```javascript$(document).re...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值