-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCF_1360F.cpp
More file actions
60 lines (55 loc) · 1.07 KB
/
CF_1360F.cpp
File metadata and controls
60 lines (55 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <functional>
#include <cstdlib>
#include <list>
#include <iomanip>
#define ll long long
using namespace std;
int main() {
int T;
cin >> T;
for (int t = 0; t < T; t++) {
int n, m;
cin >> n >> m;
vector<string> strs;
for (int i = 0; i < n; i++) {
string str;
cin >> str;
strs.push_back(str);
}
bool isFound = false;
for (int i = 0; i < m; i++) {
for (int j = 0; j < 26; j++) {
string strTemp = strs[0];
strTemp[i] = 'a' + j;
int maxDiff = 0;
for (int k = 0; k < n; k++) {
int diffCnt = 0;
for (int l = 0; l < m; l++) {
if (strTemp[l] != strs[k][l]) {
diffCnt++;
}
}
maxDiff = max(maxDiff, diffCnt);
}
if (maxDiff <= 1) {
cout << strTemp << endl;
isFound = true;
break;
}
}
if (isFound) break;
}
if (!isFound) {
cout << -1 << endl;
}
}
}