CF412C.Pattern
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Developers often face with regular expression patterns. A pattern is usually defined as a string consisting of characters and metacharacters that sets the rules for your search. These patterns are most often used to check whether a particular string meets the certain rules.
In this task, a pattern will be a string consisting of small English letters and question marks ('?'). The question mark in the pattern is a metacharacter that denotes an arbitrary small letter of the English alphabet. We will assume that a string matches the pattern if we can transform the string into the pattern by replacing the question marks by the appropriate characters. For example, string aba matches patterns: ???, ??a, a?a, aba.
Programmers that work for the R1 company love puzzling each other (and themselves) with riddles. One of them is as follows: you are given n patterns of the same length, you need to find a pattern that contains as few question marks as possible, and intersects with each of the given patterns. Two patterns intersect if there is a string that matches both the first and the second pattern. Can you solve this riddle?
程序员经常需要处理正则表达式模式。模式通常被定义为一个由字符和元字符组成的字符串,用于设定搜索规则。这些模式最常用于检查某个特定字符串是否满足某些规则。
在本题中,模式是一个仅由小写英文字母和问号(?)组成的字符串。模式中的问号是一个元字符,表示任意一个小写英文字母。我们称一个字符串与模式匹配,当且仅当我们能通过将模式中的问号替换为适当的字符,使该字符串与模式完全一致。例如,字符串 aba 与以下模式匹配:???、??a、a?a、aba。
R1 公司的程序员喜欢用谜题互相(以及自我)挑战。其中一道谜题如下:给你 n 个等长的模式,你需要找出一个模式,它所含的问号数量尽可能少,且与所有给定的 n 个模式均相交。两个模式相交,是指存在至少一个字符串,它同时与这两个模式匹配。你能解开这道谜题吗?
输入格式
The first line contains a single integer n (1 ≤ n ≤ 105) — the number of patterns. Next n lines contain the patterns.
It is guaranteed that the patterns can only consist of small English letters and symbols '?'. All patterns are non-empty and have the same length. The total length of all the patterns does not exceed 105 characters.
第一行包含一个整数 n(1≤n≤105)—— 表示模式的数量。接下来的 n 行包含这些模式。
保证每个模式仅由小写英文字母和字符 ? 组成。所有模式均非空,且长度相同。所有模式的总长度不超过 105 个字符。
输出格式
In a single line print the answer to the problem — the pattern with the minimal number of signs '?', which intersects with each of the given ones. If there are several answers, print any of them.
在一行中输出该问题的答案——即与所有给定模式均相交、且包含最少数量字符 '?' 的模式。若存在多个答案,输出其中任意一个即可。
输入输出样例
输入#1
2 ?ab ??b
输出#1
xab
输入#2
2 a b
输出#2
?
输入#3
1 ?a?b
输出#3
cacb
说明/提示
Consider the first example. Pattern xab intersects with each of the given patterns. Pattern ??? also intersects with each of the given patterns, but it contains more question signs, hence it is not an optimal answer. Clearly, xab is the optimal answer, because it doesn't contain any question sign. There are a lot of other optimal answers, for example: aab, bab, cab, dab and so on.
考虑第一个例子。模式 xab 与所有给定的模式均相交。模式 ??? 同样与所有给定的模式相交,但它包含更多的问号,因此不是最优答案。显然,xab 是最优答案,因为它不包含任何问号。还有很多其他的最优答案,例如:aab、bab、cab、dab 等等。
输入解题思路,AI测评打分。不知道怎么写?