A13540 | Spy-string
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given $n$ strings $a_1, a_2, \ldots, a_n$ : all of them have the same length $m$ . The strings consist of lowercase English letters.
Find any string $s$ of length $m$ such that each of the given $n$ strings differs from $s$ in at most one position. Formally, for each given string $a_i$ , there is no more than one position $j$ such that $a_i[j] \ne s[j]$ .
Note that the desired string $s$ may be equal to one of the given strings $a_i$ , or it may differ from all the given strings.
For example, if you have the strings abac and zbab, then the answer to the problem might be the string abab, which differs from the first only by the last character, and from the second only by the first.
Find any string $s$ of length $m$ such that each of the given $n$ strings differs from $s$ in at most one position. Formally, for each given string $a_i$ , there is no more than one position $j$ such that $a_i[j] \ne s[j]$ .
Note that the desired string $s$ may be equal to one of the given strings $a_i$ , or it may differ from all the given strings.
For example, if you have the strings abac and zbab, then the answer to the problem might be the string abab, which differs from the first only by the last character, and from the second only by the first.
输入格式
The first line contains an integer $t$ ( $1 \le t \le 100$ ) — the number of test cases. Then $t$ test cases follow.
Each test case starts with a line containing two positive integers $n$ ( $1 \le n \le 10$ ) and $m$ ( $1 \le m \le 10$ ) — the number of strings and their length.
Then follow $n$ strings $a_i$ , one per line. Each of them has length $m$ and consists of lowercase English letters.
Each test case starts with a line containing two positive integers $n$ ( $1 \le n \le 10$ ) and $m$ ( $1 \le m \le 10$ ) — the number of strings and their length.
Then follow $n$ strings $a_i$ , one per line. Each of them has length $m$ and consists of lowercase English letters.
输出格式
Print $t$ answers to the test cases. Each answer (if it exists) is a string of length $m$ consisting of lowercase English letters. If there are several answers, print any of them. If the answer does not exist, print "-1" ("minus one", without quotes).
输入输出样例
输入 #1
5 2 4 abac zbab 2 4 aaaa bbbb 3 3 baa aaa aab 2 2 ab bb 3 1 a b c
输出 #1
abab -1 aaa ab z
The first test case was explained in the statement.
In the second test case, the answer does not exist.
In the second test case, the answer does not exist.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted