output
stringlengths 52
181k
| instruction
stringlengths 296
182k
|
---|---|
#include <bits/stdc++.h>
using namespace std;
string s, s2;
int main() {
int n;
cin >> n >> s;
for (int i = 1; i < n; i++) {
cin >> s2;
for (int j = 0; s[j] != '\0'; j++) {
if (s[j] == '?')
s[j] = s2[j];
else if (s2[j] == '?')
;
else if (s[j] != s2[j])
s[j] = -1;
}
}
for (int i = 0; s[i] != '\0'; i++) {
if (s[i] == '?') s[i] = 'a';
if (s[i] == -1) s[i] = '?';
}
cout << s << endl;
return 0;
}
|
### Prompt
Please create a solution in cpp to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string s, s2;
int main() {
int n;
cin >> n >> s;
for (int i = 1; i < n; i++) {
cin >> s2;
for (int j = 0; s[j] != '\0'; j++) {
if (s[j] == '?')
s[j] = s2[j];
else if (s2[j] == '?')
;
else if (s[j] != s2[j])
s[j] = -1;
}
}
for (int i = 0; s[i] != '\0'; i++) {
if (s[i] == '?') s[i] = 'a';
if (s[i] == -1) s[i] = '?';
}
cout << s << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n, i, j, sz;
string ans, s1;
char str[100007];
unordered_set<char> st[100007];
int main() {
cin >> n;
for (i = 1; i <= n; i++) {
scanf("%s", str);
sz = strlen(str);
for (j = 0; j <= sz - 1; j++)
if (str[j] != '?') st[j].insert(str[j]);
}
for (i = 0; i <= sz - 1; i++)
if (st[i].size() == 1)
printf("%c", *st[i].begin());
else if (st[i].size() == 0)
printf("a");
else
printf("?");
return 0;
}
|
### Prompt
Create a solution in CPP for the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, i, j, sz;
string ans, s1;
char str[100007];
unordered_set<char> st[100007];
int main() {
cin >> n;
for (i = 1; i <= n; i++) {
scanf("%s", str);
sz = strlen(str);
for (j = 0; j <= sz - 1; j++)
if (str[j] != '?') st[j].insert(str[j]);
}
for (i = 0; i <= sz - 1; i++)
if (st[i].size() == 1)
printf("%c", *st[i].begin());
else if (st[i].size() == 0)
printf("a");
else
printf("?");
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
string ans;
string t;
for (int i = 0; i < n; i++) {
cin >> t;
if (i == 0) {
ans = t;
continue;
}
for (int j = 0; j < t.size(); j++)
if (ans[j] == '?')
ans[j] = t[j];
else if (ans[j] == t[j] || t[j] == '?')
ans[j] = ans[j];
else
ans[j] = '.';
}
for (int i = 0; i < ans.size(); i++)
if (ans[i] == '.')
ans[i] = '?';
else if (ans[i] == '?')
ans[i] = 'a';
ios_base::sync_with_stdio(false);
printf("%s", ans.c_str());
return 0;
}
|
### Prompt
Your challenge is to write a CPP solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
string ans;
string t;
for (int i = 0; i < n; i++) {
cin >> t;
if (i == 0) {
ans = t;
continue;
}
for (int j = 0; j < t.size(); j++)
if (ans[j] == '?')
ans[j] = t[j];
else if (ans[j] == t[j] || t[j] == '?')
ans[j] = ans[j];
else
ans[j] = '.';
}
for (int i = 0; i < ans.size(); i++)
if (ans[i] == '.')
ans[i] = '?';
else if (ans[i] == '?')
ans[i] = 'a';
ios_base::sync_with_stdio(false);
printf("%s", ans.c_str());
return 0;
}
```
|
#include <bits/stdc++.h>
int main() {
char str[100005];
char real[100005];
int n, i, j, x;
scanf("%d", &n);
scanf("%s", str);
x = strlen(str);
strcpy(real, str);
for (j = 1; j < n; j++) {
scanf("%s", str);
for (i = 0; i < x; i++) {
if (str[i] == '?' || str[i] == real[i]) continue;
if (real[i] == '?')
real[i] = str[i];
else
real[i] = '@';
}
}
for (i = 0; i < x; i++) {
if (real[i] == '@')
real[i] = '?';
else if (real[i] == '?')
real[i] = 'x';
}
printf("%s", real);
return 0;
}
|
### Prompt
Generate a cpp solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
int main() {
char str[100005];
char real[100005];
int n, i, j, x;
scanf("%d", &n);
scanf("%s", str);
x = strlen(str);
strcpy(real, str);
for (j = 1; j < n; j++) {
scanf("%s", str);
for (i = 0; i < x; i++) {
if (str[i] == '?' || str[i] == real[i]) continue;
if (real[i] == '?')
real[i] = str[i];
else
real[i] = '@';
}
}
for (i = 0; i < x; i++) {
if (real[i] == '@')
real[i] = '?';
else if (real[i] == '?')
real[i] = 'x';
}
printf("%s", real);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
char s[100005], ans[100005];
int main() {
int n, i, j;
while (scanf("%d", &n) != EOF) {
for (i = 0; i < n; i++) {
scanf("%s", s);
if (i == 0) {
for (j = 0; s[j]; j++) ans[j] = '?';
ans[j] = 0;
}
for (j = 0; s[j]; j++) {
if (ans[j] == '?') {
ans[j] = s[j];
continue;
}
if (s[j] == '?') continue;
if (ans[j] == '-') continue;
if (ans[j] == s[j]) continue;
if (ans[j] != s[j]) ans[j] = '-';
}
}
for (i = 0; s[i]; i++)
printf("%c", ans[i] == '-' ? '?' : (ans[i] == '?' ? 'a' : ans[i]));
printf("\n");
}
return 0;
}
|
### Prompt
Create a solution in Cpp for the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
char s[100005], ans[100005];
int main() {
int n, i, j;
while (scanf("%d", &n) != EOF) {
for (i = 0; i < n; i++) {
scanf("%s", s);
if (i == 0) {
for (j = 0; s[j]; j++) ans[j] = '?';
ans[j] = 0;
}
for (j = 0; s[j]; j++) {
if (ans[j] == '?') {
ans[j] = s[j];
continue;
}
if (s[j] == '?') continue;
if (ans[j] == '-') continue;
if (ans[j] == s[j]) continue;
if (ans[j] != s[j]) ans[j] = '-';
}
}
for (i = 0; s[i]; i++)
printf("%c", ans[i] == '-' ? '?' : (ans[i] == '?' ? 'a' : ans[i]));
printf("\n");
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:200000000")
int val[100100];
int main() {
int n;
scanf("%d", &n);
int len = 0;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
len = (int)(s).size();
for (int j = 0, maxj = (int)(s).size(); j < maxj; j++) {
if (s[j] == '?' && val[j] == 0)
val[j] = 1;
else if (s[j] != '?') {
if (val[j] != s[j] && val[j] != 1 && val[j] != 0)
val[j] = 1000;
else if (val[j] == 1 || val[j] == 0)
val[j] = s[j];
}
}
}
for (int i = 0; i < len; i++) {
if (val[i] == 1)
printf("a");
else if (val[i] == 1000)
printf("?");
else
printf("%c", val[i]);
}
return 0;
}
|
### Prompt
Construct a Cpp code solution to the problem outlined:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:200000000")
int val[100100];
int main() {
int n;
scanf("%d", &n);
int len = 0;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
len = (int)(s).size();
for (int j = 0, maxj = (int)(s).size(); j < maxj; j++) {
if (s[j] == '?' && val[j] == 0)
val[j] = 1;
else if (s[j] != '?') {
if (val[j] != s[j] && val[j] != 1 && val[j] != 0)
val[j] = 1000;
else if (val[j] == 1 || val[j] == 0)
val[j] = s[j];
}
}
}
for (int i = 0; i < len; i++) {
if (val[i] == 1)
printf("a");
else if (val[i] == 1000)
printf("?");
else
printf("%c", val[i]);
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
char ar[1000001];
int main() {
int n, f = 0, len;
scanf("%d", &n);
string s;
for (int i = 0; i < n; i++) {
cin >> s;
len = s.size();
for (int i = 0; i < s.size(); i++) {
if (s[i] != '?' && s[i] != ar[i] && ar[i] != '\0')
ar[i] = '?';
else if (s[i] != '?')
ar[i] = s[i], f++;
}
}
for (int i = 0; i < len; i++)
if (ar[i] == '\0') ar[i] = 'x';
ar[len] = '\0';
puts(ar);
return 0;
}
|
### Prompt
Please formulate a cpp solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
char ar[1000001];
int main() {
int n, f = 0, len;
scanf("%d", &n);
string s;
for (int i = 0; i < n; i++) {
cin >> s;
len = s.size();
for (int i = 0; i < s.size(); i++) {
if (s[i] != '?' && s[i] != ar[i] && ar[i] != '\0')
ar[i] = '?';
else if (s[i] != '?')
ar[i] = s[i], f++;
}
}
for (int i = 0; i < len; i++)
if (ar[i] == '\0') ar[i] = 'x';
ar[len] = '\0';
puts(ar);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int N = 100500;
int d[27][N];
char a[N];
int n;
int main() {
scanf("%d\n", &n);
int len = 0;
for (int i = 0; i < n; ++i) {
gets(a);
len = strlen(a);
for (int j = 0; j < len; ++j) {
if (a[j] == '?')
d[0][j]++;
else
d[a[j] - 'a' + 1][j]++;
}
}
for (int i = 0; i < len; ++i) {
int id = -1, kol = 0;
for (int j = 1; j <= 26; ++j) {
if (d[j][i] > 0) id = j, kol++;
}
if (kol == 0) {
printf("a");
} else if (kol == 1)
printf("%c", char(id + 'a' - 1));
else
printf("?");
}
return 0;
}
|
### Prompt
Construct a cpp code solution to the problem outlined:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 100500;
int d[27][N];
char a[N];
int n;
int main() {
scanf("%d\n", &n);
int len = 0;
for (int i = 0; i < n; ++i) {
gets(a);
len = strlen(a);
for (int j = 0; j < len; ++j) {
if (a[j] == '?')
d[0][j]++;
else
d[a[j] - 'a' + 1][j]++;
}
}
for (int i = 0; i < len; ++i) {
int id = -1, kol = 0;
for (int j = 1; j <= 26; ++j) {
if (d[j][i] > 0) id = j, kol++;
}
if (kol == 0) {
printf("a");
} else if (kol == 1)
printf("%c", char(id + 'a' - 1));
else
printf("?");
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int n;
cin >> n;
vector<int> V;
vector<bool> B;
for (int i = 0; i < n; i++) {
string S;
cin >> S;
if (i == 0) {
V.resize((int)S.size(), -1);
B.resize((int)S.size(), 0);
}
for (int j = 0; j < (int)S.size(); j++) {
if (S[j] != '?') {
if (V[j] == -1)
V[j] = S[j];
else if (V[j] != S[j]) {
B[j] = 1;
V[j] = S[j];
}
}
}
}
for (int i = 0; i < (int)V.size(); i++) {
if (V[i] == -1)
cout << 'a';
else {
if (B[i])
cout << '?';
else {
char c = V[i];
cout << c;
}
}
}
cout << '\n';
return 0;
}
|
### Prompt
Your task is to create a Cpp solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int n;
cin >> n;
vector<int> V;
vector<bool> B;
for (int i = 0; i < n; i++) {
string S;
cin >> S;
if (i == 0) {
V.resize((int)S.size(), -1);
B.resize((int)S.size(), 0);
}
for (int j = 0; j < (int)S.size(); j++) {
if (S[j] != '?') {
if (V[j] == -1)
V[j] = S[j];
else if (V[j] != S[j]) {
B[j] = 1;
V[j] = S[j];
}
}
}
}
for (int i = 0; i < (int)V.size(); i++) {
if (V[i] == -1)
cout << 'a';
else {
if (B[i])
cout << '?';
else {
char c = V[i];
cout << c;
}
}
}
cout << '\n';
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace ::std;
const int N = 100000 + 5;
int n;
char s[N];
char ans[N];
bool needed[N];
int main(void) {
memset(ans, '?', sizeof ans);
scanf("%d", &n);
scanf("%s", s);
int len = strlen(s);
ans[len] = '\0';
for (int j = 0; j < len; j++) {
if (s[j] != '?') ans[j] = s[j];
}
for (int i = 1; i < n; i++) {
scanf("%s", s);
for (int j = 0; j < len; j++) {
if (s[j] == '?') continue;
if (ans[j] == '?') {
ans[j] = s[j];
} else {
if (s[j] != ans[j]) {
needed[j] = true;
}
}
}
}
for (int i = 0; i < len; i++) {
if (needed[i]) ans[i] = '?';
if (ans[i] == '?' && !needed[i]) ans[i] = 'a';
}
printf("%s\n", ans);
return 0;
}
|
### Prompt
Construct a CPP code solution to the problem outlined:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace ::std;
const int N = 100000 + 5;
int n;
char s[N];
char ans[N];
bool needed[N];
int main(void) {
memset(ans, '?', sizeof ans);
scanf("%d", &n);
scanf("%s", s);
int len = strlen(s);
ans[len] = '\0';
for (int j = 0; j < len; j++) {
if (s[j] != '?') ans[j] = s[j];
}
for (int i = 1; i < n; i++) {
scanf("%s", s);
for (int j = 0; j < len; j++) {
if (s[j] == '?') continue;
if (ans[j] == '?') {
ans[j] = s[j];
} else {
if (s[j] != ans[j]) {
needed[j] = true;
}
}
}
}
for (int i = 0; i < len; i++) {
if (needed[i]) ans[i] = '?';
if (ans[i] == '?' && !needed[i]) ans[i] = 'a';
}
printf("%s\n", ans);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
string str[111111], str2;
map<int, char> m;
int cnt[26];
int main() {
int j, n;
cin >> n;
for (int i = 0; i < n; i++) cin >> str[i];
int len = str[0].length();
for (j = 0; j < len; j++) {
vector<char> v;
memset(cnt, 0, sizeof(cnt));
int cnt1 = 0;
for (int i = 0; i < n; i++) {
if (str[i][j] != '?') {
if (!v.size() || v[0] != str[i][j]) v.push_back(str[i][j]);
if (v.size() == 2) break;
} else
++cnt1;
}
if (v.size() == 2)
cout << '?';
else if (v.size() == 1)
cout << v[0];
else if (cnt1 == n)
cout << 'x';
else
cout << '?';
}
return 0;
}
|
### Prompt
Please provide a cpp coded solution to the problem described below:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string str[111111], str2;
map<int, char> m;
int cnt[26];
int main() {
int j, n;
cin >> n;
for (int i = 0; i < n; i++) cin >> str[i];
int len = str[0].length();
for (j = 0; j < len; j++) {
vector<char> v;
memset(cnt, 0, sizeof(cnt));
int cnt1 = 0;
for (int i = 0; i < n; i++) {
if (str[i][j] != '?') {
if (!v.size() || v[0] != str[i][j]) v.push_back(str[i][j]);
if (v.size() == 2) break;
} else
++cnt1;
}
if (v.size() == 2)
cout << '?';
else if (v.size() == 1)
cout << v[0];
else if (cnt1 == n)
cout << 'x';
else
cout << '?';
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int cmpfunc(const void *a, const void *b) { return *(int *)a - *(int *)b; }
int main() {
int n, i;
string s, s1;
cin >> n >> s;
if (n == 1) {
for (i = 0; i < s.length(); i++) {
if (s[i] == '?')
putchar('a');
else
putchar(s[i]);
}
putchar(10);
return 0;
} else {
n--;
while (n--) {
cin >> s1;
for (i = 0; i < s1.length(); i++) {
if (s[i] != s1[i] && s[i] != '?' && s1[i] != '?') {
s[i] = '.';
} else if (s[i] != s1[i]) {
if (s1[i] != '?') s[i] = s1[i];
}
}
}
}
for (i = 0; i < s.length(); i++) {
if (s[i] == '.')
cout << '?';
else if (s[i] == '?')
cout << 'a';
else
cout << s[i];
}
putchar(10);
return 0;
}
|
### Prompt
Your task is to create a Cpp solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int cmpfunc(const void *a, const void *b) { return *(int *)a - *(int *)b; }
int main() {
int n, i;
string s, s1;
cin >> n >> s;
if (n == 1) {
for (i = 0; i < s.length(); i++) {
if (s[i] == '?')
putchar('a');
else
putchar(s[i]);
}
putchar(10);
return 0;
} else {
n--;
while (n--) {
cin >> s1;
for (i = 0; i < s1.length(); i++) {
if (s[i] != s1[i] && s[i] != '?' && s1[i] != '?') {
s[i] = '.';
} else if (s[i] != s1[i]) {
if (s1[i] != '?') s[i] = s1[i];
}
}
}
}
for (i = 0; i < s.length(); i++) {
if (s[i] == '.')
cout << '?';
else if (s[i] == '?')
cout << 'a';
else
cout << s[i];
}
putchar(10);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, n, k, fl, t, j;
char a, b, zim, c, r;
string str, ss;
scanf("%d", &k);
for (int i = 0; i <= k - 1; i++) {
cin >> ss;
n = ss.size();
str += ss;
}
k = n;
n = str.size();
for (j = 0; j < k; j++) {
fl = 0, t = 0;
for (i = j; i < n; i += k) {
a = str[i];
if (t && isalpha(a) && zim != a) fl = 1;
if (isalpha(a) && !t) zim = a, t = 1;
if (fl) break;
}
c = '?', r = 'z';
if (fl)
printf("%c", c);
else
printf("%c", (!t) ? r : zim);
}
cout << endl;
return 0;
}
|
### Prompt
Your task is to create a cpp solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, n, k, fl, t, j;
char a, b, zim, c, r;
string str, ss;
scanf("%d", &k);
for (int i = 0; i <= k - 1; i++) {
cin >> ss;
n = ss.size();
str += ss;
}
k = n;
n = str.size();
for (j = 0; j < k; j++) {
fl = 0, t = 0;
for (i = j; i < n; i += k) {
a = str[i];
if (t && isalpha(a) && zim != a) fl = 1;
if (isalpha(a) && !t) zim = a, t = 1;
if (fl) break;
}
c = '?', r = 'z';
if (fl)
printf("%c", c);
else
printf("%c", (!t) ? r : zim);
}
cout << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
int n;
cin >> n;
vector<string> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
string ans;
for (int i = 0; i < v[0].size(); i++) ans += ' ';
for (int i = 0; i < n; i++) {
for (int j = 0; j < v[i].size(); j++) {
if (v[i][j] == '?') continue;
if (ans[j] == ' ')
ans[j] = v[i][j];
else if (ans[j] != v[i][j])
ans[j] = '?';
}
}
for (int i = 0; i < ans.size(); i++)
if (ans[i] == ' ') ans[i] = 'a';
cout << ans << endl;
return 0;
}
|
### Prompt
Generate a CPP solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
int n;
cin >> n;
vector<string> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
string ans;
for (int i = 0; i < v[0].size(); i++) ans += ' ';
for (int i = 0; i < n; i++) {
for (int j = 0; j < v[i].size(); j++) {
if (v[i][j] == '?') continue;
if (ans[j] == ' ')
ans[j] = v[i][j];
else if (ans[j] != v[i][j])
ans[j] = '?';
}
}
for (int i = 0; i < ans.size(); i++)
if (ans[i] == ' ') ans[i] = 'a';
cout << ans << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
using namespace std;
int n, r;
char s[100111];
char X[100111];
int main() {
cin >> n;
memset(X, 'X', sizeof(X));
for (int i = 1; i <= n; i++) {
scanf("%s", s);
int len = strlen(s);
X[len] = '\0';
for (int j = 0; j < len; j++)
if (s[j] != '?') {
if (X[j] == 'X' or X[j] == s[j])
X[j] = s[j];
else
X[j] = '?';
}
}
int len = strlen(X);
for (int i = 0; i < len; i++)
if (X[i] == 'X') X[i] = 'x';
printf("%s\n", X);
}
|
### Prompt
Please formulate a CPP solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
using namespace std;
int n, r;
char s[100111];
char X[100111];
int main() {
cin >> n;
memset(X, 'X', sizeof(X));
for (int i = 1; i <= n; i++) {
scanf("%s", s);
int len = strlen(s);
X[len] = '\0';
for (int j = 0; j < len; j++)
if (s[j] != '?') {
if (X[j] == 'X' or X[j] == s[j])
X[j] = s[j];
else
X[j] = '?';
}
}
int len = strlen(X);
for (int i = 0; i < len; i++)
if (X[i] == 'X') X[i] = 'x';
printf("%s\n", X);
}
```
|
#include <bits/stdc++.h>
using namespace std;
float max(long long a, long long b) {
if (a > b)
return (float)a;
else
return (float)b;
}
int min(int a, int b) {
if (a < b)
return a;
else
return b;
}
void solve() {}
int main() {
int n;
cin >> n;
string s;
cin >> s;
int l = s.length();
--n;
while (n--) {
string s2;
cin >> s2;
for (int i = 0; i < l; i++) {
if (s[i] == 0 || s[i] == '?' || s[i] == s2[i])
s[i] = s2[i];
else if (s2[i] == '?')
continue;
else
s[i] = -1;
}
}
for (int i = 0; i < l; i++) {
if (s[i] == '?') s[i] = 'a';
if (s[i] == -1) s[i] = '?';
cout << s[i];
}
return 0;
}
|
### Prompt
Construct a Cpp code solution to the problem outlined:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
float max(long long a, long long b) {
if (a > b)
return (float)a;
else
return (float)b;
}
int min(int a, int b) {
if (a < b)
return a;
else
return b;
}
void solve() {}
int main() {
int n;
cin >> n;
string s;
cin >> s;
int l = s.length();
--n;
while (n--) {
string s2;
cin >> s2;
for (int i = 0; i < l; i++) {
if (s[i] == 0 || s[i] == '?' || s[i] == s2[i])
s[i] = s2[i];
else if (s2[i] == '?')
continue;
else
s[i] = -1;
}
}
for (int i = 0; i < l; i++) {
if (s[i] == '?') s[i] = 'a';
if (s[i] == -1) s[i] = '?';
cout << s[i];
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
vector<string> patterns(n);
for (int i = 0; i < n; ++i) {
cin >> patterns[i];
}
string res = patterns[0];
for (int i = 0; i < res.length(); ++i) {
res[i] = '!';
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < res.length(); ++j) {
if (patterns[i][j] != '?') {
if (res[j] == '!') {
res[j] = patterns[i][j];
} else if (res[j] != '!' && res[j] != patterns[i][j]) {
res[j] = '?';
}
}
}
}
for (int i = 0; i < res.length(); ++i) {
if (res[i] == '!') {
res[i] = 'a';
}
}
cout << res << "\n";
return 0;
}
|
### Prompt
Please create a solution in CPP to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
vector<string> patterns(n);
for (int i = 0; i < n; ++i) {
cin >> patterns[i];
}
string res = patterns[0];
for (int i = 0; i < res.length(); ++i) {
res[i] = '!';
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < res.length(); ++j) {
if (patterns[i][j] != '?') {
if (res[j] == '!') {
res[j] = patterns[i][j];
} else if (res[j] != '!' && res[j] != patterns[i][j]) {
res[j] = '?';
}
}
}
}
for (int i = 0; i < res.length(); ++i) {
if (res[i] == '!') {
res[i] = 'a';
}
}
cout << res << "\n";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
string s[100010];
for (long long i = 0; i < n; i++) cin >> s[i];
char res[100010];
int sz = s[0].size();
for (long long j = 0; j < sz; j++) {
set<char> ss;
char c;
for (long long i = 0; i < n; i++)
if (isalpha(s[i][j])) ss.insert(s[i][j]), c = s[i][j];
if (ss.size() == 0)
res[j] = 'q';
else if (ss.size() > 1)
res[j] = '?';
else
res[j] = c;
}
for (long long i = 0; i < sz; i++) cout << res[i];
return 0;
}
|
### Prompt
Construct a cpp code solution to the problem outlined:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
string s[100010];
for (long long i = 0; i < n; i++) cin >> s[i];
char res[100010];
int sz = s[0].size();
for (long long j = 0; j < sz; j++) {
set<char> ss;
char c;
for (long long i = 0; i < n; i++)
if (isalpha(s[i][j])) ss.insert(s[i][j]), c = s[i][j];
if (ss.size() == 0)
res[j] = 'q';
else if (ss.size() > 1)
res[j] = '?';
else
res[j] = c;
}
for (long long i = 0; i < sz; i++) cout << res[i];
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
char str[100005];
char out[100005];
int n;
for (int i = 0; i < 100000; i++) out[i] = '?';
while (~scanf("%d", &n)) {
scanf("%s", &out);
int l = strlen(out);
for (int i = 1; i < n; i++) {
scanf("%s", &str);
for (int j = 0; j < l; j++) {
if (out[j] == '!') continue;
if (str[j] == '?') continue;
if (out[j] == '?')
out[j] = str[j];
else if (out[j] == str[j])
continue;
else
out[j] = '!';
}
}
for (int i = 0; i < l; i++) {
if (out[i] == '?')
printf("a");
else if (out[i] == '!')
printf("?");
else
printf("%c", out[i]);
}
printf("\n");
}
}
|
### Prompt
Your challenge is to write a CPP solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
char str[100005];
char out[100005];
int n;
for (int i = 0; i < 100000; i++) out[i] = '?';
while (~scanf("%d", &n)) {
scanf("%s", &out);
int l = strlen(out);
for (int i = 1; i < n; i++) {
scanf("%s", &str);
for (int j = 0; j < l; j++) {
if (out[j] == '!') continue;
if (str[j] == '?') continue;
if (out[j] == '?')
out[j] = str[j];
else if (out[j] == str[j])
continue;
else
out[j] = '!';
}
}
for (int i = 0; i < l; i++) {
if (out[i] == '?')
printf("a");
else if (out[i] == '!')
printf("?");
else
printf("%c", out[i]);
}
printf("\n");
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
int ans[100005];
int coun[100005];
int main() {
int t;
cin >> t;
int n;
while (t--) {
string str;
cin >> str;
n = str.length();
for (int i = 0; i < str.length(); i++) {
if (str[i] != '?' && (coun[i] == 0 || coun[i] == str[i]))
coun[i] = str[i];
else if (str[i] != '?' && (coun[i] != 0 && coun[i] != str[i]))
coun[i] = 1;
}
}
for (int i = 0; i < n; i++) {
if (coun[i] == 0)
cout << 'a';
else if (coun[i] == 1)
cout << "?";
else
cout << char(coun[i]);
}
}
|
### Prompt
Please create a solution in Cpp to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int ans[100005];
int coun[100005];
int main() {
int t;
cin >> t;
int n;
while (t--) {
string str;
cin >> str;
n = str.length();
for (int i = 0; i < str.length(); i++) {
if (str[i] != '?' && (coun[i] == 0 || coun[i] == str[i]))
coun[i] = str[i];
else if (str[i] != '?' && (coun[i] != 0 && coun[i] != str[i]))
coun[i] = 1;
}
}
for (int i = 0; i < n; i++) {
if (coun[i] == 0)
cout << 'a';
else if (coun[i] == 1)
cout << "?";
else
cout << char(coun[i]);
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n;
string s[100500];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> s[i];
}
int nn = s[1].size();
string t = "";
for (int j = 0; j < nn; j++) {
bool ok = 0;
char ch = '#';
map<char, bool> m;
m.clear();
for (int i = 1; i <= n; i++) {
if (s[i][j] != '?') m[s[i][j]] = 1, ch = s[i][j];
if (m.size() > 1) {
cout << '?';
ok = 1;
break;
}
}
if (m.size() > 1 && !ok) {
cout << '?';
ok = 1;
continue;
}
if (ok) continue;
if (m.empty()) {
for (int j = 0; j < 26; j++) {
if (m.count(j + 'a') == 0) {
cout << char(j + 'a');
break;
}
}
} else {
cout << ch;
}
}
return 0;
}
|
### Prompt
Create a solution in cpp for the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
string s[100500];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> s[i];
}
int nn = s[1].size();
string t = "";
for (int j = 0; j < nn; j++) {
bool ok = 0;
char ch = '#';
map<char, bool> m;
m.clear();
for (int i = 1; i <= n; i++) {
if (s[i][j] != '?') m[s[i][j]] = 1, ch = s[i][j];
if (m.size() > 1) {
cout << '?';
ok = 1;
break;
}
}
if (m.size() > 1 && !ok) {
cout << '?';
ok = 1;
continue;
}
if (ok) continue;
if (m.empty()) {
for (int j = 0; j < 26; j++) {
if (m.count(j + 'a') == 0) {
cout << char(j + 'a');
break;
}
}
} else {
cout << ch;
}
}
return 0;
}
```
|
#include <bits/stdc++.h>
time_t waktu = clock();
void gettime() {
printf("\nTime : %.2lf", (clock() - waktu) / double(CLOCKS_PER_SEC));
}
bool comp(int a, int b) { return (a > b); }
using namespace std;
int main() {
int n, x, i, j, cek[100005] = {};
char data1[100005] = {}, data2[100005] = {};
scanf("%d", &n);
scanf("%s", &data1);
x = strlen(data1);
for (i = 2; i <= n; i++) {
scanf("%s", &data2);
for (j = 0; j < x; j++) {
if (data1[j] == '?' && data2[j] != '?' && cek[j] == 0)
data1[j] = data2[j];
else if (data1[j] != '?' && data2[j] != '?' && data1[j] != data2[j] &&
cek[j] == 0) {
cek[j] = 1;
data1[j] = '?';
}
}
}
for (i = 0; i < x; i++) {
if (data1[i] == '?' && cek[i] == 0) data1[i] = 'a';
}
printf("%s", data1);
return 0;
}
|
### Prompt
Your challenge is to write a cpp solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
time_t waktu = clock();
void gettime() {
printf("\nTime : %.2lf", (clock() - waktu) / double(CLOCKS_PER_SEC));
}
bool comp(int a, int b) { return (a > b); }
using namespace std;
int main() {
int n, x, i, j, cek[100005] = {};
char data1[100005] = {}, data2[100005] = {};
scanf("%d", &n);
scanf("%s", &data1);
x = strlen(data1);
for (i = 2; i <= n; i++) {
scanf("%s", &data2);
for (j = 0; j < x; j++) {
if (data1[j] == '?' && data2[j] != '?' && cek[j] == 0)
data1[j] = data2[j];
else if (data1[j] != '?' && data2[j] != '?' && data1[j] != data2[j] &&
cek[j] == 0) {
cek[j] = 1;
data1[j] = '?';
}
}
}
for (i = 0; i < x; i++) {
if (data1[i] == '?' && cek[i] == 0) data1[i] = 'a';
}
printf("%s", data1);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int n;
string str;
cin >> n;
cin >> str;
int k = str.size();
char mas[k];
for (int i = 0; i < k; ++i) {
mas[i] = '?';
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < k; ++j) {
if (mas[j] != '.' && str[j] != '?' && mas[j] != '?' && mas[j] != str[j])
mas[j] = '.';
if (mas[j] != '.' && str[j] != '?' && mas[j] == '?') mas[j] = str[j];
}
if (i != n - 1) cin >> str;
}
for (int i = 0; i < k; ++i) {
if (mas[i] == '?') cout << "x";
if (mas[i] != '?' && mas[i] != '.') cout << mas[i];
if (mas[i] == '.') cout << "?";
}
return 0;
}
|
### Prompt
Develop a solution in CPP to the problem described below:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int n;
string str;
cin >> n;
cin >> str;
int k = str.size();
char mas[k];
for (int i = 0; i < k; ++i) {
mas[i] = '?';
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < k; ++j) {
if (mas[j] != '.' && str[j] != '?' && mas[j] != '?' && mas[j] != str[j])
mas[j] = '.';
if (mas[j] != '.' && str[j] != '?' && mas[j] == '?') mas[j] = str[j];
}
if (i != n - 1) cin >> str;
}
for (int i = 0; i < k; ++i) {
if (mas[i] == '?') cout << "x";
if (mas[i] != '?' && mas[i] != '.') cout << mas[i];
if (mas[i] == '.') cout << "?";
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
char ch[100100];
char mark[100100];
int main() {
memset(mark, 0, sizeof(mark));
int n, l;
scanf("%d", &n);
while (n--) {
scanf("%s", ch);
l = strlen(ch);
for (int i = 0; i < l; i++) {
if (ch[i] == '?')
continue;
else {
if (mark[i] == 0) {
mark[i] = ch[i];
continue;
}
if (mark[i] != ch[i]) {
mark[i] = '?';
}
}
}
}
mark[l] = 0;
for (int i = 0; i < l; i++) {
if (mark[i] == 0)
printf("a");
else
printf("%c", mark[i]);
}
printf("\n");
return 0;
}
|
### Prompt
Your challenge is to write a Cpp solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
char ch[100100];
char mark[100100];
int main() {
memset(mark, 0, sizeof(mark));
int n, l;
scanf("%d", &n);
while (n--) {
scanf("%s", ch);
l = strlen(ch);
for (int i = 0; i < l; i++) {
if (ch[i] == '?')
continue;
else {
if (mark[i] == 0) {
mark[i] = ch[i];
continue;
}
if (mark[i] != ch[i]) {
mark[i] = '?';
}
}
}
}
mark[l] = 0;
for (int i = 0; i < l; i++) {
if (mark[i] == 0)
printf("a");
else
printf("%c", mark[i]);
}
printf("\n");
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
while (a && b) a > b ? a %= b : b %= a;
return a + b;
}
long long int lcm(long long int a, long long int b) {
return (max(a, b) / gcd(a, b)) * min(a, b);
}
long long int power(long long int a, long long int b) {
long long int res = 1;
while (b != 0) {
if (b % 2 != 0) {
res = (res * a) % 1000000007;
b--;
} else {
a = (a * a) % 1000000007;
b /= 2;
}
}
return res;
}
int main() {
ios::sync_with_stdio(0);
;
long long int i, j, k, c = 0, n, m, d = 0, l, r, z, w, e = 0, t, prev, next,
mid, x, y;
cin >> n;
vector<string> s(n);
vector<pair<long long int, long long int>> v;
set<long long int> sp;
stack<long long int> st;
queue<long long int> q;
for (i = 0; i < n; i++) {
cin >> s[i];
}
for (i = 0; i < s[0].size(); i++) {
map<char, long long int> mp1, mp2;
c = 0;
for (j = 0; j < n; j++) {
if (s[j][i] == '?')
c++;
else
mp1[s[j][i]]++;
}
if (c == n)
cout << "a";
else if (mp1.size() == 1)
cout << mp1.begin()->first;
else
cout << "?";
}
return 0;
}
|
### Prompt
Please provide a Cpp coded solution to the problem described below:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
while (a && b) a > b ? a %= b : b %= a;
return a + b;
}
long long int lcm(long long int a, long long int b) {
return (max(a, b) / gcd(a, b)) * min(a, b);
}
long long int power(long long int a, long long int b) {
long long int res = 1;
while (b != 0) {
if (b % 2 != 0) {
res = (res * a) % 1000000007;
b--;
} else {
a = (a * a) % 1000000007;
b /= 2;
}
}
return res;
}
int main() {
ios::sync_with_stdio(0);
;
long long int i, j, k, c = 0, n, m, d = 0, l, r, z, w, e = 0, t, prev, next,
mid, x, y;
cin >> n;
vector<string> s(n);
vector<pair<long long int, long long int>> v;
set<long long int> sp;
stack<long long int> st;
queue<long long int> q;
for (i = 0; i < n; i++) {
cin >> s[i];
}
for (i = 0; i < s[0].size(); i++) {
map<char, long long int> mp1, mp2;
c = 0;
for (j = 0; j < n; j++) {
if (s[j][i] == '?')
c++;
else
mp1[s[j][i]]++;
}
if (c == n)
cout << "a";
else if (mp1.size() == 1)
cout << mp1.begin()->first;
else
cout << "?";
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e7 + 7;
const int mx = 1234567;
char ans[mx], a[mx];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
int n;
cin >> n;
int len;
memset(ans, '*', sizeof(ans));
for (int i = 0; i < n; i++) {
cin >> a;
len = strlen(a);
for (int j = 0; a[j]; j++)
if (a[j] != '?') {
if (ans[j] == '*')
ans[j] = a[j];
else if (ans[j] != a[j])
ans[j] = '?';
}
}
for (int i = 0; i < len; i++) {
if (ans[i] == '*')
cout << "a";
else
cout << ans[i];
}
cout << endl;
return 0;
}
|
### Prompt
Generate a Cpp solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e7 + 7;
const int mx = 1234567;
char ans[mx], a[mx];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
int n;
cin >> n;
int len;
memset(ans, '*', sizeof(ans));
for (int i = 0; i < n; i++) {
cin >> a;
len = strlen(a);
for (int j = 0; a[j]; j++)
if (a[j] != '?') {
if (ans[j] == '*')
ans[j] = a[j];
else if (ans[j] != a[j])
ans[j] = '?';
}
}
for (int i = 0; i < len; i++) {
if (ans[i] == '*')
cout << "a";
else
cout << ans[i];
}
cout << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int qtot[100001];
int atot[100001][27];
int main() {
int n, i, j, l;
char str[100003];
memset(atot, 0, sizeof atot);
while (~scanf("%d", &n)) {
for (i = 0; i < n; ++i) {
scanf("%s", str);
l = strlen(str);
for (j = 0; j < l; ++j)
if (str[j] == '?')
qtot[j]++;
else
atot[j][str[j] - 'a']++;
}
for (i = 0; i < l; ++i) {
if (qtot[i] == n)
printf("a");
else {
int t = 0;
char ch;
for (j = 0; j < 26; ++j) {
if (atot[i][j] > 0) {
t++;
ch = j + 'a';
}
}
if (t == 1)
printf("%c", ch);
else
printf("?");
}
}
printf("\n");
}
return 0;
}
|
### Prompt
Generate a cpp solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int qtot[100001];
int atot[100001][27];
int main() {
int n, i, j, l;
char str[100003];
memset(atot, 0, sizeof atot);
while (~scanf("%d", &n)) {
for (i = 0; i < n; ++i) {
scanf("%s", str);
l = strlen(str);
for (j = 0; j < l; ++j)
if (str[j] == '?')
qtot[j]++;
else
atot[j][str[j] - 'a']++;
}
for (i = 0; i < l; ++i) {
if (qtot[i] == n)
printf("a");
else {
int t = 0;
char ch;
for (j = 0; j < 26; ++j) {
if (atot[i][j] > 0) {
t++;
ch = j + 'a';
}
}
if (t == 1)
printf("%c", ch);
else
printf("?");
}
}
printf("\n");
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n, f[1000005][30];
char s[1000005];
int main() {
scanf("%d", &n);
int len;
for (int i = 0; i < n; i++) {
scanf(" %s", s);
for (int j = 0; s[j]; j++) {
if (s[j] == '?')
f[j][26]++;
else
f[j][s[j] - 'a']++;
}
if (i == 0) len = strlen(s);
}
for (int i = 0; i < len; i++) {
int c = 0;
char o = 'a';
for (int j = 0; j < 26; j++) {
if (f[i][j] > 0) {
c++;
o = j + 'a';
}
}
if (c < 2)
printf("%c", o);
else
printf("?");
}
printf("\n");
}
|
### Prompt
Generate a Cpp solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, f[1000005][30];
char s[1000005];
int main() {
scanf("%d", &n);
int len;
for (int i = 0; i < n; i++) {
scanf(" %s", s);
for (int j = 0; s[j]; j++) {
if (s[j] == '?')
f[j][26]++;
else
f[j][s[j] - 'a']++;
}
if (i == 0) len = strlen(s);
}
for (int i = 0; i < len; i++) {
int c = 0;
char o = 'a';
for (int j = 0; j < 26; j++) {
if (f[i][j] > 0) {
c++;
o = j + 'a';
}
}
if (c < 2)
printf("%c", o);
else
printf("?");
}
printf("\n");
}
```
|
#include <bits/stdc++.h>
using namespace std;
vector<string> vec;
int main() {
int n;
cin >> n;
vec.resize(n);
for (int i = 0; i < n; i++) cin >> vec[i];
for (int i = 0; i < int(vec[0].size()); i++) {
char c = '-';
for (int j = 0; j < (int)vec.size(); j++) {
if (vec[j][i] == '?') {
} else {
if (c == '-')
c = vec[j][i];
else if (c != vec[j][i]) {
c = '?';
break;
}
}
}
if (c == '-')
cout << "a";
else
cout << c;
}
}
|
### Prompt
Develop a solution in CPP to the problem described below:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
vector<string> vec;
int main() {
int n;
cin >> n;
vec.resize(n);
for (int i = 0; i < n; i++) cin >> vec[i];
for (int i = 0; i < int(vec[0].size()); i++) {
char c = '-';
for (int j = 0; j < (int)vec.size(); j++) {
if (vec[j][i] == '?') {
} else {
if (c == '-')
c = vec[j][i];
else if (c != vec[j][i]) {
c = '?';
break;
}
}
}
if (c == '-')
cout << "a";
else
cout << c;
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
set<char> st[100005];
int cnt[100005];
char ss[100005];
int main() {
int n;
ios_base::sync_with_stdio(0);
;
cin >> n;
string s;
int len = 0;
for (int i = 0; i < n; i++) {
cin >> s;
len = s.size();
for (int j = 0; j < s.size(); j++) {
if (s[j] == '?') {
cnt[j]++;
continue;
}
st[j].insert(s[j]);
ss[j] = s[j];
}
}
for (int i = 0; i < len; i++) {
if (cnt[i] == n) {
cout << "a";
} else if (st[i].size() > 1) {
cout << "?";
} else {
cout << ss[i];
}
}
cout << "\n";
return 0;
}
|
### Prompt
Please formulate a cpp solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
set<char> st[100005];
int cnt[100005];
char ss[100005];
int main() {
int n;
ios_base::sync_with_stdio(0);
;
cin >> n;
string s;
int len = 0;
for (int i = 0; i < n; i++) {
cin >> s;
len = s.size();
for (int j = 0; j < s.size(); j++) {
if (s[j] == '?') {
cnt[j]++;
continue;
}
st[j].insert(s[j]);
ss[j] = s[j];
}
}
for (int i = 0; i < len; i++) {
if (cnt[i] == n) {
cout << "a";
} else if (st[i].size() > 1) {
cout << "?";
} else {
cout << ss[i];
}
}
cout << "\n";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int max_n = 1e5 + 10;
int n;
int len;
string s[max_n];
string ans;
int main() {
ios_base::sync_with_stdio(false);
cin >> n;
for (int i = 0; i < n; ++i) cin >> s[i];
len = s[0].length();
ans.resize(len);
for (int i = 0; i < len; ++i) {
bool good = true;
char c = '?';
for (int j = 0; j < n; ++j)
if (s[j][i] != '?') {
if (c == '?') {
c = s[j][i];
} else {
if (c != s[j][i]) {
good = false;
}
}
}
if (good) {
if (c == '?') {
ans[i] = 'a';
} else {
ans[i] = c;
}
} else {
ans[i] = '?';
}
}
cout << ans << endl;
return 0;
}
|
### Prompt
Your task is to create a cpp solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int max_n = 1e5 + 10;
int n;
int len;
string s[max_n];
string ans;
int main() {
ios_base::sync_with_stdio(false);
cin >> n;
for (int i = 0; i < n; ++i) cin >> s[i];
len = s[0].length();
ans.resize(len);
for (int i = 0; i < len; ++i) {
bool good = true;
char c = '?';
for (int j = 0; j < n; ++j)
if (s[j][i] != '?') {
if (c == '?') {
c = s[j][i];
} else {
if (c != s[j][i]) {
good = false;
}
}
}
if (good) {
if (c == '?') {
ans[i] = 'a';
} else {
ans[i] = c;
}
} else {
ans[i] = '?';
}
}
cout << ans << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, i, f, g, j;
cin >> n;
char temp1;
std::string a[n];
for (i = 0; i < n; i++) cin >> a[i];
k = a[0].size();
for (j = 0; j < k; j++) {
f = 0;
g = 0;
for (i = 0; i < n; i++) {
if (a[i][j] != '?' && f == 0) {
temp1 = a[i][j];
f = 1;
} else if (a[i][j] != '?' && f == 1) {
if (a[i][j] != temp1) {
g = 1;
break;
}
}
}
if (g == 1)
cout << "?";
else if (f == 0)
cout << "x";
else
cout << temp1;
}
cout << endl;
return 0;
}
|
### Prompt
Generate a Cpp solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, i, f, g, j;
cin >> n;
char temp1;
std::string a[n];
for (i = 0; i < n; i++) cin >> a[i];
k = a[0].size();
for (j = 0; j < k; j++) {
f = 0;
g = 0;
for (i = 0; i < n; i++) {
if (a[i][j] != '?' && f == 0) {
temp1 = a[i][j];
f = 1;
} else if (a[i][j] != '?' && f == 1) {
if (a[i][j] != temp1) {
g = 1;
break;
}
}
}
if (g == 1)
cout << "?";
else if (f == 0)
cout << "x";
else
cout << temp1;
}
cout << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int base = 1e9;
const int maxn = 1e5;
const int logn = 20;
const int inf = (1 << 31) - 1;
const int alpha = 26;
const int my_hash = 29;
const long long l_inf = (1 << 62);
const long long mod = 1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-9;
int main() {
ios_base::sync_with_stdio();
int n, t;
cin >> n;
vector<string> m(n);
for (int i = int(0); i < int(n); i++) cin >> m[i];
string ans = "";
t = m[0].size();
for (int i = int(0); i < int(t); i++) {
char a = 0;
for (int j = int(0); j < int(n); j++) {
if (m[j][i] == '?') continue;
if (!a) {
a = m[j][i];
continue;
}
if (m[j][i] != a) {
a = 1;
break;
}
}
if (a == 1) ans.push_back('?');
if (a > 1) ans.push_back(a);
if (a == 0) ans.push_back('a');
}
cout << ans;
}
|
### Prompt
Your task is to create a CPP solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int base = 1e9;
const int maxn = 1e5;
const int logn = 20;
const int inf = (1 << 31) - 1;
const int alpha = 26;
const int my_hash = 29;
const long long l_inf = (1 << 62);
const long long mod = 1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-9;
int main() {
ios_base::sync_with_stdio();
int n, t;
cin >> n;
vector<string> m(n);
for (int i = int(0); i < int(n); i++) cin >> m[i];
string ans = "";
t = m[0].size();
for (int i = int(0); i < int(t); i++) {
char a = 0;
for (int j = int(0); j < int(n); j++) {
if (m[j][i] == '?') continue;
if (!a) {
a = m[j][i];
continue;
}
if (m[j][i] != a) {
a = 1;
break;
}
}
if (a == 1) ans.push_back('?');
if (a > 1) ans.push_back(a);
if (a == 0) ans.push_back('a');
}
cout << ans;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n, k;
string a[100500];
int main() {
cin >> n;
getline(cin, a[0]);
for (int i = 0; i < n; ++i) getline(cin, a[i]);
int len = a[0].size();
for (int j = 0; j < len; ++j) {
char ans = '/';
for (int i = 0; i < n; ++i)
if (a[i][j] != '?') {
if (a[i][j] == ans || ans == '/')
ans = a[i][j];
else
ans = '?';
}
if (ans == '/') ans = 'a';
printf("%c", ans);
}
printf("\n");
return 0;
}
|
### Prompt
Your challenge is to write a CPP solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, k;
string a[100500];
int main() {
cin >> n;
getline(cin, a[0]);
for (int i = 0; i < n; ++i) getline(cin, a[i]);
int len = a[0].size();
for (int j = 0; j < len; ++j) {
char ans = '/';
for (int i = 0; i < n; ++i)
if (a[i][j] != '?') {
if (a[i][j] == ans || ans == '/')
ans = a[i][j];
else
ans = '?';
}
if (ans == '/') ans = 'a';
printf("%c", ans);
}
printf("\n");
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
vector<string> str;
int n;
string res;
int main() {
int i, j;
scanf("%d", &n);
str.resize(n + 1);
for (i = 1; i <= n; ++i) {
cin >> str[i];
}
int len = str[1].size();
for (i = 0; i <= len - 1; ++i) {
char c = str[1][i];
bool match = 1;
for (j = 2; j <= n; ++j) {
if (c == '?') {
c = str[j][i];
} else {
if (c == str[j][i] || str[j][i] == '?') {
continue;
} else {
match = 0;
break;
}
}
}
if (!match)
res.push_back('?');
else
res.push_back(c == '?' ? 'x' : c);
}
cout << res << endl;
}
|
### Prompt
Please create a solution in cpp to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
vector<string> str;
int n;
string res;
int main() {
int i, j;
scanf("%d", &n);
str.resize(n + 1);
for (i = 1; i <= n; ++i) {
cin >> str[i];
}
int len = str[1].size();
for (i = 0; i <= len - 1; ++i) {
char c = str[1][i];
bool match = 1;
for (j = 2; j <= n; ++j) {
if (c == '?') {
c = str[j][i];
} else {
if (c == str[j][i] || str[j][i] == '?') {
continue;
} else {
match = 0;
break;
}
}
}
if (!match)
res.push_back('?');
else
res.push_back(c == '?' ? 'x' : c);
}
cout << res << endl;
}
```
|
#include <bits/stdc++.h>
using namespace std;
char str[100005], ans[100005];
int main() {
int n, m;
while (cin >> n) {
scanf("%s", str);
m = strlen(str);
for (int i = 0; i < m; i++) {
ans[i] = 0;
}
for (int i = 0; i < n; i++) {
if (i) scanf("%s", str);
for (int j = 0; j < m; j++) {
if ((ans[j] == 0 && str[j] != '?')) {
ans[j] = str[j];
}
if (ans[j] != 0 && ans[j] != str[j] && str[j] != '?') {
ans[j] = '?';
}
}
}
for (int i = 0; i < m; i++) {
if (ans[i] == 0) {
ans[i] = 'a';
}
cout << ans[i];
}
cout << endl;
}
return 0;
}
|
### Prompt
Create a solution in Cpp for the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
char str[100005], ans[100005];
int main() {
int n, m;
while (cin >> n) {
scanf("%s", str);
m = strlen(str);
for (int i = 0; i < m; i++) {
ans[i] = 0;
}
for (int i = 0; i < n; i++) {
if (i) scanf("%s", str);
for (int j = 0; j < m; j++) {
if ((ans[j] == 0 && str[j] != '?')) {
ans[j] = str[j];
}
if (ans[j] != 0 && ans[j] != str[j] && str[j] != '?') {
ans[j] = '?';
}
}
}
for (int i = 0; i < m; i++) {
if (ans[i] == 0) {
ans[i] = 'a';
}
cout << ans[i];
}
cout << endl;
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string patterns[n];
for (int i = 0; i < n; i++) cin >> patterns[i];
int l = patterns[0].size();
string pattern(l, 'a');
for (int j = 0; j < l; j++) {
char seen = patterns[0][j];
bool same = true;
for (int i = 1; i < n; i++) {
if (seen == '?' && patterns[i][j] != '?') {
seen = patterns[i][j];
} else if (patterns[i][j] != '?' && patterns[i][j] != seen) {
pattern[j] = '?';
same = false;
break;
}
}
if (same && seen != '?') pattern[j] = seen;
}
cout << pattern << endl;
return 0;
}
|
### Prompt
Create a solution in cpp for the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string patterns[n];
for (int i = 0; i < n; i++) cin >> patterns[i];
int l = patterns[0].size();
string pattern(l, 'a');
for (int j = 0; j < l; j++) {
char seen = patterns[0][j];
bool same = true;
for (int i = 1; i < n; i++) {
if (seen == '?' && patterns[i][j] != '?') {
seen = patterns[i][j];
} else if (patterns[i][j] != '?' && patterns[i][j] != seen) {
pattern[j] = '?';
same = false;
break;
}
}
if (same && seen != '?') pattern[j] = seen;
}
cout << pattern << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
int main() {
char cad[100000], temp[100000];
int n, j, tam;
scanf("%d\n", &n);
for (int i = 0; i < 100000; i++) {
cad[i] = '?';
}
if (n > 1) {
for (int i = 0; i < n; i++) {
scanf("%s", temp);
j = 0;
while (temp[j] != '\0' && j < 100000) {
if (cad[j] == '?') {
cad[j] = temp[j];
} else {
if (cad[j] != temp[j]) {
if (temp[j] != '?') {
cad[j] = '$';
}
}
}
j++;
}
if (i == 0) tam = j;
}
} else {
scanf("%s", cad);
tam = 0;
while (cad[tam] != '\0' && tam < 100000) tam++;
}
for (int i = 0; i < tam; i++) {
if (cad[i] == '?') {
printf("x");
} else {
if (cad[i] == '$') {
printf("?");
} else {
printf("%c", cad[i]);
}
}
}
return 0;
}
|
### Prompt
In cpp, your task is to solve the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
int main() {
char cad[100000], temp[100000];
int n, j, tam;
scanf("%d\n", &n);
for (int i = 0; i < 100000; i++) {
cad[i] = '?';
}
if (n > 1) {
for (int i = 0; i < n; i++) {
scanf("%s", temp);
j = 0;
while (temp[j] != '\0' && j < 100000) {
if (cad[j] == '?') {
cad[j] = temp[j];
} else {
if (cad[j] != temp[j]) {
if (temp[j] != '?') {
cad[j] = '$';
}
}
}
j++;
}
if (i == 0) tam = j;
}
} else {
scanf("%s", cad);
tam = 0;
while (cad[tam] != '\0' && tam < 100000) tam++;
}
for (int i = 0; i < tam; i++) {
if (cad[i] == '?') {
printf("x");
} else {
if (cad[i] == '$') {
printf("?");
} else {
printf("%c", cad[i]);
}
}
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main(void) {
char ans[100000 + 5], str[100000 + 5];
memset(ans, '.', sizeof(ans));
int n, i;
cin >> n;
gets(str);
while (n--) {
gets(str);
for (i = 0; str[i]; i++) {
if (ans[i] == '?') {
continue;
}
if (str[i] != '?') {
if (ans[i] == '.') {
ans[i] = str[i];
} else if (ans[i] != str[i]) {
ans[i] = '?';
}
}
}
ans[i] = '\0';
}
for (i = 0; ans[i]; i++) {
if (ans[i] == '.') {
putchar('a');
} else {
putchar(ans[i]);
}
}
putchar('\n');
return 0;
}
|
### Prompt
Please formulate a Cpp solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main(void) {
char ans[100000 + 5], str[100000 + 5];
memset(ans, '.', sizeof(ans));
int n, i;
cin >> n;
gets(str);
while (n--) {
gets(str);
for (i = 0; str[i]; i++) {
if (ans[i] == '?') {
continue;
}
if (str[i] != '?') {
if (ans[i] == '.') {
ans[i] = str[i];
} else if (ans[i] != str[i]) {
ans[i] = '?';
}
}
}
ans[i] = '\0';
}
for (i = 0; ans[i]; i++) {
if (ans[i] == '.') {
putchar('a');
} else {
putchar(ans[i]);
}
}
putchar('\n');
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s[n], ans;
for (int i = 0; i < n; i++) cin >> s[i];
for (int i = 0; i < s[0].length(); i++) {
bool t = true;
set<char> ch;
char it = '?';
for (int j = 0; j < n; j++) {
if (s[j][i] != '?') {
it = s[j][i];
}
if (s[j][i] != '?') ch.insert(s[j][i]), it = s[j][i];
if (ch.size() > 1) {
t = false;
ch.clear();
break;
}
}
if (t) {
if (ch.size())
ans += it;
else
ans += 'b';
} else
ans += '?';
}
cout << ans << endl;
}
|
### Prompt
Develop a solution in CPP to the problem described below:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s[n], ans;
for (int i = 0; i < n; i++) cin >> s[i];
for (int i = 0; i < s[0].length(); i++) {
bool t = true;
set<char> ch;
char it = '?';
for (int j = 0; j < n; j++) {
if (s[j][i] != '?') {
it = s[j][i];
}
if (s[j][i] != '?') ch.insert(s[j][i]), it = s[j][i];
if (ch.size() > 1) {
t = false;
ch.clear();
break;
}
}
if (t) {
if (ch.size())
ans += it;
else
ans += 'b';
} else
ans += '?';
}
cout << ans << endl;
}
```
|
#include <bits/stdc++.h>
using namespace std;
double PI = acos(-1);
double EPS = 1e-7;
int INF = 1000000000;
int MOD = 1000000007;
int MAXINT = 2147483647;
long long INFLL = 1000000000000000000LL;
long long MAXLL = 9223372036854775807LL;
int mx[8] = {-1, 1, 0, 0, -1, -1, 1, 1};
int my[8] = {0, 0, -1, 1, -1, 1, -1, 1};
int pos[100005][256];
char s[100005];
int main() {
int n;
scanf("%d", &n);
int len;
for (int(a) = (1); (a) <= (n); (a)++) {
scanf("%s", s);
len = strlen(s);
for (int(b) = (0); (b) <= (len - 1); (b)++) {
pos[b][s[b]]++;
}
}
for (int(a) = (0); (a) <= (len - 1); (a)++) {
if (pos[a]['?'] == n)
printf("a");
else {
int sisa = n - pos[a]['?'];
int sam = 0;
for (int(b) = (0); (b) <= (255); (b)++) {
if (b != '?' && pos[a][b] == sisa) {
sam = 1;
printf("%c", b);
break;
}
}
if (!sam) printf("?");
}
}
printf("\n");
}
|
### Prompt
Develop a solution in cpp to the problem described below:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
double PI = acos(-1);
double EPS = 1e-7;
int INF = 1000000000;
int MOD = 1000000007;
int MAXINT = 2147483647;
long long INFLL = 1000000000000000000LL;
long long MAXLL = 9223372036854775807LL;
int mx[8] = {-1, 1, 0, 0, -1, -1, 1, 1};
int my[8] = {0, 0, -1, 1, -1, 1, -1, 1};
int pos[100005][256];
char s[100005];
int main() {
int n;
scanf("%d", &n);
int len;
for (int(a) = (1); (a) <= (n); (a)++) {
scanf("%s", s);
len = strlen(s);
for (int(b) = (0); (b) <= (len - 1); (b)++) {
pos[b][s[b]]++;
}
}
for (int(a) = (0); (a) <= (len - 1); (a)++) {
if (pos[a]['?'] == n)
printf("a");
else {
int sisa = n - pos[a]['?'];
int sam = 0;
for (int(b) = (0); (b) <= (255); (b)++) {
if (b != '?' && pos[a][b] == sisa) {
sam = 1;
printf("%c", b);
break;
}
}
if (!sam) printf("?");
}
}
printf("\n");
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a;
string s, z;
cin >> a >> s;
for (int i = 1; i < a && cin >> z; i++)
for (int j = 0; j < s.length(); j++)
if (s[j] == '?')
s[j] = z[j];
else if (z[j] != '?' && s[j] != z[j])
s[j] = '*';
for (int i = 0; i < s.length(); i++)
if (s[i] == '?')
cout << "x";
else if (s[i] == '*')
cout << "?";
else
cout << s[i];
return 0;
}
|
### Prompt
In Cpp, your task is to solve the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int a;
string s, z;
cin >> a >> s;
for (int i = 1; i < a && cin >> z; i++)
for (int j = 0; j < s.length(); j++)
if (s[j] == '?')
s[j] = z[j];
else if (z[j] != '?' && s[j] != z[j])
s[j] = '*';
for (int i = 0; i < s.length(); i++)
if (s[i] == '?')
cout << "x";
else if (s[i] == '*')
cout << "?";
else
cout << s[i];
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, i, j, k, m;
cin >> n;
vector<string> s(n);
for (i = 0; i < n; i++) cin >> s[i];
m = s[0].length();
string ans = s[0];
for (i = 0; i < m; i++) {
set<char> ss;
for (j = 0; j < n; j++) ss.insert(s[j][i]);
if (ss.size() == 1) {
if (*ss.begin() == '?')
ans[i] = 'w';
else
ans[i] = *ss.begin();
} else {
ss.erase('?');
if (ss.size() == 1)
ans[i] = *ss.begin();
else
ans[i] = '?';
}
}
cout << ans << "\n";
return 0;
}
|
### Prompt
Create a solution in Cpp for the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, i, j, k, m;
cin >> n;
vector<string> s(n);
for (i = 0; i < n; i++) cin >> s[i];
m = s[0].length();
string ans = s[0];
for (i = 0; i < m; i++) {
set<char> ss;
for (j = 0; j < n; j++) ss.insert(s[j][i]);
if (ss.size() == 1) {
if (*ss.begin() == '?')
ans[i] = 'w';
else
ans[i] = *ss.begin();
} else {
ss.erase('?');
if (ss.size() == 1)
ans[i] = *ss.begin();
else
ans[i] = '?';
}
}
cout << ans << "\n";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const int mod = (int)1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-9;
string second[100005];
int n;
string ans = "";
int a[200];
int main() {
scanf("%d\n", &n);
for (int i = 0; i < n; i++) getline(cin, second[i]);
for (int i = 0; i < second[0].length(); i++) {
memset(a, 0, sizeof a);
for (int j = 0; j < n; j++) {
a[second[j][i]]++;
}
int k = 0;
char c;
for (int j = 'a'; j <= 'z'; j++)
if (a[j]) {
k++;
c = (char)(j);
}
if (k == 0)
ans += 'a';
else if (k == 1)
ans += c;
else
ans += '?';
}
cout << ans << endl;
return 0;
}
|
### Prompt
Please provide a CPP coded solution to the problem described below:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const int mod = (int)1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-9;
string second[100005];
int n;
string ans = "";
int a[200];
int main() {
scanf("%d\n", &n);
for (int i = 0; i < n; i++) getline(cin, second[i]);
for (int i = 0; i < second[0].length(); i++) {
memset(a, 0, sizeof a);
for (int j = 0; j < n; j++) {
a[second[j][i]]++;
}
int k = 0;
char c;
for (int j = 'a'; j <= 'z'; j++)
if (a[j]) {
k++;
c = (char)(j);
}
if (k == 0)
ans += 'a';
else if (k == 1)
ans += c;
else
ans += '?';
}
cout << ans << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
set<int> ss[100002];
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> s;
for (int j = 0; j < s.size(); ++j)
if (s[j] != '?' and ss[j].size() <= 1) ss[j].insert(s[j]);
}
for (int i = 0; i < s.size(); ++i)
if (ss[i].empty())
printf("x");
else if (ss[i].size() == 1)
printf("%c", *ss[i].begin());
else
printf("?");
puts("");
return 0;
}
|
### Prompt
Your challenge is to write a CPP solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
set<int> ss[100002];
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> s;
for (int j = 0; j < s.size(); ++j)
if (s[j] != '?' and ss[j].size() <= 1) ss[j].insert(s[j]);
}
for (int i = 0; i < s.size(); ++i)
if (ss[i].empty())
printf("x");
else if (ss[i].size() == 1)
printf("%c", *ss[i].begin());
else
printf("?");
puts("");
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int N;
cin >> N;
string S[N];
for (int i = 0; i < N; i++) {
cin >> S[i];
}
int j = 0, k = 0, count = 0, count_1 = 0, count_Q = 0;
char Compare;
for (j = 0; j < S[0].size(); j++) {
for (k = 0; k < N; k++) {
if (S[k][j] == '?') {
count_Q++;
} else {
if (count_1 == 0) {
count_1++;
Compare = S[k][j];
} else {
if (S[k][j] != Compare) {
count++;
break;
}
}
}
}
if (count_Q == N) {
cout << "a";
count_Q -= count_Q;
count -= count;
count_1 -= count_1;
} else {
if (count == 0) {
cout << Compare;
count -= count;
count_1 -= count_1;
count_Q -= count_Q;
} else {
cout << "?";
count -= count;
count_1 -= count_1;
count_Q -= count_Q;
}
}
}
cout << "\n";
return 0;
}
|
### Prompt
Construct a cpp code solution to the problem outlined:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int N;
cin >> N;
string S[N];
for (int i = 0; i < N; i++) {
cin >> S[i];
}
int j = 0, k = 0, count = 0, count_1 = 0, count_Q = 0;
char Compare;
for (j = 0; j < S[0].size(); j++) {
for (k = 0; k < N; k++) {
if (S[k][j] == '?') {
count_Q++;
} else {
if (count_1 == 0) {
count_1++;
Compare = S[k][j];
} else {
if (S[k][j] != Compare) {
count++;
break;
}
}
}
}
if (count_Q == N) {
cout << "a";
count_Q -= count_Q;
count -= count;
count_1 -= count_1;
} else {
if (count == 0) {
cout << Compare;
count -= count;
count_1 -= count_1;
count_Q -= count_Q;
} else {
cout << "?";
count -= count;
count_1 -= count_1;
count_Q -= count_Q;
}
}
}
cout << "\n";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, n, l, k;
std::ios::sync_with_stdio(false);
cin >> n;
string j[n], s;
for (i = 0; i < n; i++) cin >> j[i];
l = j[0].length();
for (i = 0; i < l; i++) {
s = "";
for (k = 0; k < n; k++) {
if (j[k][i] == '?')
continue;
else if (s == "")
s = j[k][i];
else if (s[0] == j[k][i])
continue;
else
s = "?";
}
if (s == "")
cout << "x";
else
cout << s;
}
return 0;
}
|
### Prompt
Your challenge is to write a CPP solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, n, l, k;
std::ios::sync_with_stdio(false);
cin >> n;
string j[n], s;
for (i = 0; i < n; i++) cin >> j[i];
l = j[0].length();
for (i = 0; i < l; i++) {
s = "";
for (k = 0; k < n; k++) {
if (j[k][i] == '?')
continue;
else if (s == "")
s = j[k][i];
else if (s[0] == j[k][i])
continue;
else
s = "?";
}
if (s == "")
cout << "x";
else
cout << s;
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
string s[100010];
for (long long i = 0; i < n; i++) cin >> s[i];
int si = s[0].size();
char res[100010];
for (long long i = 0; i < si; i++) {
set<char> ss;
char c;
for (long long j = 0; j < n; j++)
if (isalpha(s[j][i])) {
ss.insert(s[j][i]);
c = s[j][i];
}
if (ss.size() == 0)
res[i] = 'x';
else if (ss.size() > 1)
res[i] = '?';
else
res[i] = c;
}
for (long long i = 0; i < si; i++) cout << res[i];
return 0;
}
|
### Prompt
Please provide a Cpp coded solution to the problem described below:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
string s[100010];
for (long long i = 0; i < n; i++) cin >> s[i];
int si = s[0].size();
char res[100010];
for (long long i = 0; i < si; i++) {
set<char> ss;
char c;
for (long long j = 0; j < n; j++)
if (isalpha(s[j][i])) {
ss.insert(s[j][i]);
c = s[j][i];
}
if (ss.size() == 0)
res[i] = 'x';
else if (ss.size() > 1)
res[i] = '?';
else
res[i] = c;
}
for (long long i = 0; i < si; i++) cout << res[i];
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
char a[100005], ans[100005];
int main() {
int n, m;
cin >> n;
while (n--) {
cin >> a;
m = strlen(a);
for (int i = 0; i < m; i++) {
if (a[i] != '?') {
if (ans[i] == 0)
ans[i] = a[i];
else if (a[i] != ans[i])
ans[i] = '?';
}
}
}
ans[m] = 0;
for (int i = 0; i < m; i++) {
if (ans[i] == 0) ans[i] = 'a';
}
cout << ans << endl;
return 0;
}
|
### Prompt
Generate a cpp solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
char a[100005], ans[100005];
int main() {
int n, m;
cin >> n;
while (n--) {
cin >> a;
m = strlen(a);
for (int i = 0; i < m; i++) {
if (a[i] != '?') {
if (ans[i] == 0)
ans[i] = a[i];
else if (a[i] != ans[i])
ans[i] = '?';
}
}
}
ans[m] = 0;
for (int i = 0; i < m; i++) {
if (ans[i] == 0) ans[i] = 'a';
}
cout << ans << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<string> a;
string s;
for (int i = 0; i < n; i++) {
cin >> s;
a.push_back(s);
}
set<char> t;
set<char>::iterator it;
for (int i = 0; i < a[0].size(); i++) {
t.clear();
for (int j = 0; j < n; j++) {
t.insert(a[j][i]);
}
it = t.begin();
if (t.size() == 1) {
if (*it == '?')
cout << 'a';
else
cout << *it;
continue;
}
if (t.size() == 2) {
if (*it == '?') {
it++;
cout << *it;
continue;
} else {
cout << '?';
continue;
}
}
cout << '?';
}
return 0;
}
|
### Prompt
Your task is to create a cpp solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<string> a;
string s;
for (int i = 0; i < n; i++) {
cin >> s;
a.push_back(s);
}
set<char> t;
set<char>::iterator it;
for (int i = 0; i < a[0].size(); i++) {
t.clear();
for (int j = 0; j < n; j++) {
t.insert(a[j][i]);
}
it = t.begin();
if (t.size() == 1) {
if (*it == '?')
cout << 'a';
else
cout << *it;
continue;
}
if (t.size() == 2) {
if (*it == '?') {
it++;
cout << *it;
continue;
} else {
cout << '?';
continue;
}
}
cout << '?';
}
return 0;
}
```
|
#include <bits/stdc++.h>
const int maxn = 100100;
char ch[maxn], ans[maxn];
int next[maxn];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < maxn; i++) {
next[i] = i + 1;
ans[i] = -1;
}
next[maxn - 1] = 0;
bool first = true;
while (n--) {
scanf("%s", ch);
int len = strlen(ch);
next[len - 1] = -1;
ans[len] = 0;
int front = maxn - 1;
int t = next[front];
while (t != -1) {
if (first)
ans[t] = ch[t] != '?' ? ch[t] : ans[t];
else {
bool flag = false;
if (ans[t] != ch[t]) {
if (ans[t] == -1 && ch[t] != '?')
ans[t] = ch[t];
else if (ch[t] != '?') {
ans[t] = '?';
next[front] = next[t];
flag = true;
}
}
if (!flag) front = t;
}
t = next[t];
}
first = false;
}
while (ans[++n] != 0)
if (ans[n] == -1) ans[n] = 'a';
printf("%s\n", ans);
return 0;
}
|
### Prompt
In cpp, your task is to solve the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
const int maxn = 100100;
char ch[maxn], ans[maxn];
int next[maxn];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < maxn; i++) {
next[i] = i + 1;
ans[i] = -1;
}
next[maxn - 1] = 0;
bool first = true;
while (n--) {
scanf("%s", ch);
int len = strlen(ch);
next[len - 1] = -1;
ans[len] = 0;
int front = maxn - 1;
int t = next[front];
while (t != -1) {
if (first)
ans[t] = ch[t] != '?' ? ch[t] : ans[t];
else {
bool flag = false;
if (ans[t] != ch[t]) {
if (ans[t] == -1 && ch[t] != '?')
ans[t] = ch[t];
else if (ch[t] != '?') {
ans[t] = '?';
next[front] = next[t];
flag = true;
}
}
if (!flag) front = t;
}
t = next[t];
}
first = false;
}
while (ans[++n] != 0)
if (ans[n] == -1) ans[n] = 'a';
printf("%s\n", ans);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
long long int pow_mod(long long int a, long long int b) {
long long int res = 1;
while (b != 0) {
if (b & 1) {
res = (res * a) % 1000000007;
}
a = (a * a) % 1000000007;
b /= 2;
}
return res;
}
void solve() {
long long int n;
cin >> n;
string s[n];
for (long long int i = 0; i < n; i++) cin >> s[i];
long long int x = s[0].size();
string temp;
for (long long int i = 0; i < x; i++) {
set<char> st;
for (long long int j = 0; j < n; j++)
if (s[j][i] != '?') st.insert(s[j][i]);
if (st.size() > 1) {
temp += '?';
} else if (st.size() == 0)
temp += 'a';
else
temp += (*st.begin());
}
cout << temp << endl;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int t;
t = 1;
while (t--) solve();
return 0;
}
|
### Prompt
In cpp, your task is to solve the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long int pow_mod(long long int a, long long int b) {
long long int res = 1;
while (b != 0) {
if (b & 1) {
res = (res * a) % 1000000007;
}
a = (a * a) % 1000000007;
b /= 2;
}
return res;
}
void solve() {
long long int n;
cin >> n;
string s[n];
for (long long int i = 0; i < n; i++) cin >> s[i];
long long int x = s[0].size();
string temp;
for (long long int i = 0; i < x; i++) {
set<char> st;
for (long long int j = 0; j < n; j++)
if (s[j][i] != '?') st.insert(s[j][i]);
if (st.size() > 1) {
temp += '?';
} else if (st.size() == 0)
temp += 'a';
else
temp += (*st.begin());
}
cout << temp << endl;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int t;
t = 1;
while (t--) solve();
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<string> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
for (int j = 0; j < v[0].size(); j++) {
char letter;
bool flag = 0;
for (int i = 0; i < n; i++) {
if (!flag && v[i][j] != '?') {
flag = 1;
letter = v[i][j];
} else if (flag && v[i][j] != '?' && v[i][j] != letter)
letter = '?';
}
if (!flag)
cout << "x";
else
cout << letter;
}
return 0;
}
|
### Prompt
Develop a solution in cpp to the problem described below:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<string> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
for (int j = 0; j < v[0].size(); j++) {
char letter;
bool flag = 0;
for (int i = 0; i < n; i++) {
if (!flag && v[i][j] != '?') {
flag = 1;
letter = v[i][j];
} else if (flag && v[i][j] != '?' && v[i][j] != letter)
letter = '?';
}
if (!flag)
cout << "x";
else
cout << letter;
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int c;
scanf("%d", &c);
string s;
cin >> s;
int tam = s.size();
for (int i = 0; i < c - 1; i++) {
for (int j = 0; j < tam; j++) {
char c;
cin >> c;
if (c != '?' && c != s[j] && s[j] != '?') {
s[j] = '0';
} else if (c != '?' && s[j] == '?') {
s[j] = c;
}
}
}
for (int i = 0; i < tam; i++) {
if (s[i] == '?')
printf("l");
else if (s[i] == '0')
printf("?");
else
printf("%c", s[i]);
}
cout << endl;
}
|
### Prompt
Please create a solution in cpp to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int c;
scanf("%d", &c);
string s;
cin >> s;
int tam = s.size();
for (int i = 0; i < c - 1; i++) {
for (int j = 0; j < tam; j++) {
char c;
cin >> c;
if (c != '?' && c != s[j] && s[j] != '?') {
s[j] = '0';
} else if (c != '?' && s[j] == '?') {
s[j] = c;
}
}
}
for (int i = 0; i < tam; i++) {
if (s[i] == '?')
printf("l");
else if (s[i] == '0')
printf("?");
else
printf("%c", s[i]);
}
cout << endl;
}
```
|
#include <bits/stdc++.h>
char str[100001], str2[100001];
int chk[100001];
int main() {
int n;
scanf("%d %s", &n, str);
for (int i = 1; i < n; i++) {
scanf(" %s", str2);
for (int j = 0; str2[j]; j++) {
if (str[j] != str2[j]) {
if (str[j] == '?' && chk[j] == 0)
str[j] = str2[j];
else if (str[j] != '?' && str2[j] != '?')
str[j] = '?', chk[j] = 1;
}
}
}
for (int i = 0; str[i]; i++) {
if (chk[i] == 0 && str[i] == '?')
printf("a");
else
printf("%c", str[i]);
}
return 0;
}
|
### Prompt
Please formulate a CPP solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
char str[100001], str2[100001];
int chk[100001];
int main() {
int n;
scanf("%d %s", &n, str);
for (int i = 1; i < n; i++) {
scanf(" %s", str2);
for (int j = 0; str2[j]; j++) {
if (str[j] != str2[j]) {
if (str[j] == '?' && chk[j] == 0)
str[j] = str2[j];
else if (str[j] != '?' && str2[j] != '?')
str[j] = '?', chk[j] = 1;
}
}
}
for (int i = 0; str[i]; i++) {
if (chk[i] == 0 && str[i] == '?')
printf("a");
else
printf("%c", str[i]);
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-11;
int dp[101111];
char res[101111];
int main() {
std::ios_base::sync_with_stdio(0);
memset(dp, -1, sizeof dp);
fill(res, res + 100001, 'a');
int n;
cin >> n;
string s;
for (int i = 0; i < n; ++i) {
cin >> s;
for (int j = 0; j < int((s).size()); ++j) {
if (res[j] == '?') continue;
if (s[j] != '?') {
if (dp[j] == -1) {
dp[j] = (s[j] - 'a');
res[j] = s[j];
} else if (dp[j] != -1) {
if (dp[j] != (s[j] - 'a')) {
res[j] = '?';
} else
res[j] = s[j];
}
}
}
}
for (int i = 0; i < int((s).size()); ++i) {
cout << res[i];
}
return 0;
}
|
### Prompt
Construct a cpp code solution to the problem outlined:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-11;
int dp[101111];
char res[101111];
int main() {
std::ios_base::sync_with_stdio(0);
memset(dp, -1, sizeof dp);
fill(res, res + 100001, 'a');
int n;
cin >> n;
string s;
for (int i = 0; i < n; ++i) {
cin >> s;
for (int j = 0; j < int((s).size()); ++j) {
if (res[j] == '?') continue;
if (s[j] != '?') {
if (dp[j] == -1) {
dp[j] = (s[j] - 'a');
res[j] = s[j];
} else if (dp[j] != -1) {
if (dp[j] != (s[j] - 'a')) {
res[j] = '?';
} else
res[j] = s[j];
}
}
}
}
for (int i = 0; i < int((s).size()); ++i) {
cout << res[i];
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int stat[100003], qmark[100003], beda[100003], n;
string s;
int main(void) {
cin >> n;
memset(stat, -1, sizeof(stat));
memset(qmark, 0, sizeof(qmark));
memset(beda, 0, sizeof(beda));
for (int i = 1; i <= n; i++) {
cin >> s;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '?')
qmark[i]++;
else {
if (stat[i] == -1) {
stat[i] = s[i] - 'a';
beda[i]++;
} else if (stat[i] != s[i] - 'a') {
beda[i]++;
}
}
}
}
for (int i = 0; i < s.length(); i++) {
if (qmark[i] == n)
cout << "x";
else if (beda[i] >= 2)
cout << "?";
else
cout << (char)(stat[i] + 'a');
}
cout << endl;
}
|
### Prompt
In CPP, your task is to solve the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int stat[100003], qmark[100003], beda[100003], n;
string s;
int main(void) {
cin >> n;
memset(stat, -1, sizeof(stat));
memset(qmark, 0, sizeof(qmark));
memset(beda, 0, sizeof(beda));
for (int i = 1; i <= n; i++) {
cin >> s;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '?')
qmark[i]++;
else {
if (stat[i] == -1) {
stat[i] = s[i] - 'a';
beda[i]++;
} else if (stat[i] != s[i] - 'a') {
beda[i]++;
}
}
}
}
for (int i = 0; i < s.length(); i++) {
if (qmark[i] == n)
cout << "x";
else if (beda[i] >= 2)
cout << "?";
else
cout << (char)(stat[i] + 'a');
}
cout << endl;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string mas[n];
for (int i = 0; i < n; ++i) cin >> mas[i];
string ans = mas[0];
int len = ans.size();
for (int i = 0; i < len; ++i) {
bool alph[26];
memset(alph, 0, sizeof(alph));
int cnt = 0;
for (int j = 0; j < n; ++j) {
if (mas[j][i] != '?') {
if (!alph[mas[j][i] - 'a']) cnt++;
alph[mas[j][i] - 'a'] = true;
}
}
if (cnt == 1) {
for (int j = 0;; ++j) {
if (alph[j]) {
ans[i] = char(j + 'a');
break;
}
}
continue;
}
if (!cnt) {
ans[i] = 'a';
continue;
}
ans[i] = '?';
}
cout << ans << endl;
return 0;
}
|
### Prompt
Please create a solution in Cpp to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string mas[n];
for (int i = 0; i < n; ++i) cin >> mas[i];
string ans = mas[0];
int len = ans.size();
for (int i = 0; i < len; ++i) {
bool alph[26];
memset(alph, 0, sizeof(alph));
int cnt = 0;
for (int j = 0; j < n; ++j) {
if (mas[j][i] != '?') {
if (!alph[mas[j][i] - 'a']) cnt++;
alph[mas[j][i] - 'a'] = true;
}
}
if (cnt == 1) {
for (int j = 0;; ++j) {
if (alph[j]) {
ans[i] = char(j + 'a');
break;
}
}
continue;
}
if (!cnt) {
ans[i] = 'a';
continue;
}
ans[i] = '?';
}
cout << ans << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
string izlaz;
int main() {
cin >> n;
cin >> izlaz;
for (int i = 0; i < izlaz.length(); ++i)
if (izlaz[i] == '?') izlaz[i] = '.';
for (int i = 1; i < n; ++i) {
cin >> s;
for (int i = 0; i < s.length(); ++i) {
if (i >= izlaz.length()) {
if (s[i] == '?')
izlaz += '.';
else
izlaz += s[i];
} else if (s[i] == '?')
continue;
else {
if (izlaz[i] == '.')
izlaz[i] = s[i];
else if (izlaz[i] != s[i])
izlaz[i] = '?';
}
}
}
for (int i = 0; i < izlaz.length(); ++i)
if (izlaz[i] == '.') izlaz[i] = 'x';
cout << izlaz;
}
|
### Prompt
Please formulate a CPP solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
string izlaz;
int main() {
cin >> n;
cin >> izlaz;
for (int i = 0; i < izlaz.length(); ++i)
if (izlaz[i] == '?') izlaz[i] = '.';
for (int i = 1; i < n; ++i) {
cin >> s;
for (int i = 0; i < s.length(); ++i) {
if (i >= izlaz.length()) {
if (s[i] == '?')
izlaz += '.';
else
izlaz += s[i];
} else if (s[i] == '?')
continue;
else {
if (izlaz[i] == '.')
izlaz[i] = s[i];
else if (izlaz[i] != s[i])
izlaz[i] = '?';
}
}
}
for (int i = 0; i < izlaz.length(); ++i)
if (izlaz[i] == '.') izlaz[i] = 'x';
cout << izlaz;
}
```
|
#include <bits/stdc++.h>
using namespace std;
char a[100000], c;
string s[100000];
int main() {
c = 'D';
int n, p, i, j;
scanf("%d", &n);
for (i = 0; i < n; i++) cin >> s[i];
p = s[0].size();
for (i = 0; i < p; i++) {
c = 'D';
for (j = 0; j < n; j++) {
if (s[j][i] != '?' && c != s[j][i] && c != 'D') {
c = '?';
break;
}
if (s[j][i] != '?') {
c = s[j][i];
}
}
if (c != 'D')
a[i] = c;
else
a[i] = 'd';
}
a[p] = '\0';
printf("%s\n", a);
return 0;
}
|
### Prompt
In Cpp, your task is to solve the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
char a[100000], c;
string s[100000];
int main() {
c = 'D';
int n, p, i, j;
scanf("%d", &n);
for (i = 0; i < n; i++) cin >> s[i];
p = s[0].size();
for (i = 0; i < p; i++) {
c = 'D';
for (j = 0; j < n; j++) {
if (s[j][i] != '?' && c != s[j][i] && c != 'D') {
c = '?';
break;
}
if (s[j][i] != '?') {
c = s[j][i];
}
}
if (c != 'D')
a[i] = c;
else
a[i] = 'd';
}
a[p] = '\0';
printf("%s\n", a);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
static vector<string> vc;
int main() {
ios_base::sync_with_stdio(0);
int n;
int a, b;
string str;
char ch;
cin >> n;
vc.resize(n);
for (int i = 0; i < n; ++i) cin >> vc[i];
for (int i = 0; i < vc[0].length(); ++i) {
a = 0;
b = 0;
for (int j = 0; j < n; ++j)
if (a == 0 && vc[j][i] != '?') {
a = 1;
ch = vc[j][i];
} else if (vc[j][i] != '?' && vc[j][i] != ch) {
b = 1;
break;
}
if (b)
str.push_back('?');
else if (!a)
str.push_back('a');
else
str.push_back(ch);
}
cout << str << endl;
return 0;
}
|
### Prompt
Your challenge is to write a cpp solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
static vector<string> vc;
int main() {
ios_base::sync_with_stdio(0);
int n;
int a, b;
string str;
char ch;
cin >> n;
vc.resize(n);
for (int i = 0; i < n; ++i) cin >> vc[i];
for (int i = 0; i < vc[0].length(); ++i) {
a = 0;
b = 0;
for (int j = 0; j < n; ++j)
if (a == 0 && vc[j][i] != '?') {
a = 1;
ch = vc[j][i];
} else if (vc[j][i] != '?' && vc[j][i] != ch) {
b = 1;
break;
}
if (b)
str.push_back('?');
else if (!a)
str.push_back('a');
else
str.push_back(ch);
}
cout << str << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
long n, l;
string s[1000000];
char c, t;
int main() {
scanf("%li", &n);
for (long i = 1; i <= n; i++) cin >> s[i];
l = s[1].size();
for (long i = 0; i < l; i++) {
c = '*';
for (long j = 1; j <= n; j++) {
t = s[j][i];
if (t != '?')
if (c == '*')
c = t;
else if (c != t)
c = '?';
}
if (c == '*') c = 'a';
printf("%c", c);
}
return 0;
}
|
### Prompt
Please formulate a Cpp solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long n, l;
string s[1000000];
char c, t;
int main() {
scanf("%li", &n);
for (long i = 1; i <= n; i++) cin >> s[i];
l = s[1].size();
for (long i = 0; i < l; i++) {
c = '*';
for (long j = 1; j <= n; j++) {
t = s[j][i];
if (t != '?')
if (c == '*')
c = t;
else if (c != t)
c = '?';
}
if (c == '*') c = 'a';
printf("%c", c);
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int maximum(int a, int b) {
if (a > b)
return a;
else
return b;
}
bool cmp(const pair<int, int>& firs, const pair<int, int>& sec) {
return firs.first < sec.first;
}
string in[100005];
char mark[100005];
int lag[100005];
int main() {
int n;
int l, i;
scanf("%d", &n);
for (i = 0; i < n; i++) {
cin >> in[i];
}
l = in[0].size();
for (i = 0; i < l; i++) {
mark[i] = in[0][i];
}
int j;
for (i = 1; i < n; i++) {
for (j = 0; j < l; j++) {
if (mark[j] == in[i][j]) {
continue;
} else {
if (mark[j] == '?' && lag[j] == 0) {
mark[j] = in[i][j];
} else if (in[i][j] == '?')
continue;
else if (mark[j] != '?' && in[i][j] != '?') {
mark[j] = '?';
lag[j] = 1;
}
}
}
}
for (i = 0; i < l; i++) {
if (lag[i] == 1)
printf("%c", mark[i]);
else {
if (mark[i] == '?')
printf("a");
else
printf("%c", mark[i]);
}
}
return 0;
}
|
### Prompt
Your challenge is to write a Cpp solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int maximum(int a, int b) {
if (a > b)
return a;
else
return b;
}
bool cmp(const pair<int, int>& firs, const pair<int, int>& sec) {
return firs.first < sec.first;
}
string in[100005];
char mark[100005];
int lag[100005];
int main() {
int n;
int l, i;
scanf("%d", &n);
for (i = 0; i < n; i++) {
cin >> in[i];
}
l = in[0].size();
for (i = 0; i < l; i++) {
mark[i] = in[0][i];
}
int j;
for (i = 1; i < n; i++) {
for (j = 0; j < l; j++) {
if (mark[j] == in[i][j]) {
continue;
} else {
if (mark[j] == '?' && lag[j] == 0) {
mark[j] = in[i][j];
} else if (in[i][j] == '?')
continue;
else if (mark[j] != '?' && in[i][j] != '?') {
mark[j] = '?';
lag[j] = 1;
}
}
}
}
for (i = 0; i < l; i++) {
if (lag[i] == 1)
printf("%c", mark[i]);
else {
if (mark[i] == '?')
printf("a");
else
printf("%c", mark[i]);
}
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int N = 2020;
int main() {
int n;
cin >> n;
vector<string> v(n);
for (long long i = 0; i < (n); i++) cin >> v[i];
string s;
for (long long i = 0; i < (v[0].size()); i++) {
int f = 0;
char c = '?';
for (long long j = 0; j < (n); j++) {
if (f == 0 && v[j][i] != '?') {
f = 1;
c = v[j][i];
} else if (f == 1 && v[j][i] != '?' && v[j][i] != c) {
f = 2;
c = '?';
break;
}
}
if (f == 0)
s += 'a';
else if (f == 1)
s += c;
else
s += '?';
}
cout << s << endl;
}
|
### Prompt
Construct a cpp code solution to the problem outlined:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2020;
int main() {
int n;
cin >> n;
vector<string> v(n);
for (long long i = 0; i < (n); i++) cin >> v[i];
string s;
for (long long i = 0; i < (v[0].size()); i++) {
int f = 0;
char c = '?';
for (long long j = 0; j < (n); j++) {
if (f == 0 && v[j][i] != '?') {
f = 1;
c = v[j][i];
} else if (f == 1 && v[j][i] != '?' && v[j][i] != c) {
f = 2;
c = '?';
break;
}
}
if (f == 0)
s += 'a';
else if (f == 1)
s += c;
else
s += '?';
}
cout << s << endl;
}
```
|
#include <bits/stdc++.h>
using namespace std;
using namespace std;
long long gcd(long long a, long long b) {
if (a < b)
return gcd(b, a);
else if (b == 0)
return a;
else
return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long pow(long long b, long long e) {
if (e == 0)
return 1;
else if (e % 2 == 0) {
long long a = pow(b, e / 2);
return a * a;
} else {
long long a = pow(b, e / 2);
return b * a * a;
}
}
long long pow_m(long long x, long long y, long long m = 1000000007) {
x = x % m;
long long res = 1;
while (y) {
if (y & 1) res = res * x;
res %= m;
y = y >> 1;
x = x * x;
x %= m;
}
return res;
}
long long modInverse(long long a, long long m) { return pow_m(a, m - 2, m); }
long long max(long long a, long long b) {
if (a >= b)
return a;
else
return b;
}
long long min(long long a, long long b) {
if (a <= b)
return a;
else
return b;
}
long long bin_coff(long long n, long long k, long long m) {
vector<vector<long long>> ans(n + 1, vector<long long>(k, 0));
for (long long i = 0; i < n + 1; i++) {
for (long long j = 0; j < min(i, k) + 1; j++) {
if (j == 0 || j == i)
ans[i][j] = 1;
else
ans[i][j] = ans[i - 1][j - 1] % m + ans[i - 1][j] % m;
}
}
return ans[n][k] % m;
}
long long inverse(long long i) {
if (i == 1) return 1;
return (1000000007 -
((1000000007 / i) * inverse(1000000007 % i)) % 1000000007 +
1000000007) %
1000000007;
}
const long long N = 10000007;
vector<bool> primes(N + 1, true);
void eren() {
primes[0] = false;
primes[1] = false;
for (long long i = 2; i * i <= N; i++) {
if (primes[i]) {
for (long long j = i * i; j <= N; j += i) primes[j] = false;
}
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
eren();
int tt = 1;
for (int it = 0; it < tt; it++) {
long long n;
cin >> n;
string s;
cin >> s;
for (long long i = 0; i < n - 1; i++) {
string t;
cin >> t;
for (long long j = 0; j < t.length(); j++) {
if (t[j] == '?') {
} else {
if (s[j] == '?')
s[j] = t[j];
else if (s[j] == t[j]) {
} else
s[j] = '*';
}
}
}
for (long long i = 0; i < s.length(); i++) {
if (s[i] == '?')
s[i] = 'a';
else if (s[i] == '*')
s[i] = '?';
}
cout << s << "\n";
}
return 0;
}
|
### Prompt
Your task is to create a CPP solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
using namespace std;
long long gcd(long long a, long long b) {
if (a < b)
return gcd(b, a);
else if (b == 0)
return a;
else
return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long pow(long long b, long long e) {
if (e == 0)
return 1;
else if (e % 2 == 0) {
long long a = pow(b, e / 2);
return a * a;
} else {
long long a = pow(b, e / 2);
return b * a * a;
}
}
long long pow_m(long long x, long long y, long long m = 1000000007) {
x = x % m;
long long res = 1;
while (y) {
if (y & 1) res = res * x;
res %= m;
y = y >> 1;
x = x * x;
x %= m;
}
return res;
}
long long modInverse(long long a, long long m) { return pow_m(a, m - 2, m); }
long long max(long long a, long long b) {
if (a >= b)
return a;
else
return b;
}
long long min(long long a, long long b) {
if (a <= b)
return a;
else
return b;
}
long long bin_coff(long long n, long long k, long long m) {
vector<vector<long long>> ans(n + 1, vector<long long>(k, 0));
for (long long i = 0; i < n + 1; i++) {
for (long long j = 0; j < min(i, k) + 1; j++) {
if (j == 0 || j == i)
ans[i][j] = 1;
else
ans[i][j] = ans[i - 1][j - 1] % m + ans[i - 1][j] % m;
}
}
return ans[n][k] % m;
}
long long inverse(long long i) {
if (i == 1) return 1;
return (1000000007 -
((1000000007 / i) * inverse(1000000007 % i)) % 1000000007 +
1000000007) %
1000000007;
}
const long long N = 10000007;
vector<bool> primes(N + 1, true);
void eren() {
primes[0] = false;
primes[1] = false;
for (long long i = 2; i * i <= N; i++) {
if (primes[i]) {
for (long long j = i * i; j <= N; j += i) primes[j] = false;
}
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
eren();
int tt = 1;
for (int it = 0; it < tt; it++) {
long long n;
cin >> n;
string s;
cin >> s;
for (long long i = 0; i < n - 1; i++) {
string t;
cin >> t;
for (long long j = 0; j < t.length(); j++) {
if (t[j] == '?') {
} else {
if (s[j] == '?')
s[j] = t[j];
else if (s[j] == t[j]) {
} else
s[j] = '*';
}
}
}
for (long long i = 0; i < s.length(); i++) {
if (s[i] == '?')
s[i] = 'a';
else if (s[i] == '*')
s[i] = '?';
}
cout << s << "\n";
}
return 0;
}
```
|
#include <bits/stdc++.h>
const int maxn = 100100;
char ch[maxn], ans[maxn];
int next[maxn];
int main() {
int n, len;
scanf("%d", &n);
for (int i = 0; i < maxn; i++) {
next[i] = i + 1;
ans[i] = -1;
}
int f = 1;
next[maxn - 1] = 0;
while (n--) {
scanf("%s", ch);
if (f == 1) {
f++;
len = strlen(ch);
}
next[len - 1] = -1;
ans[len] = 0;
int front = maxn - 1, t = next[maxn - 1];
while (t != -1) {
bool flag = false;
if (ans[t] != ch[t]) {
if (ans[t] == -1 && ch[t] != '?')
ans[t] = ch[t];
else if (ch[t] != '?') {
ans[t] = '?';
next[front] = next[t];
flag = true;
}
}
if (!flag) front = t;
t = next[t];
}
}
while (ans[++n] != 0)
if (ans[n] == -1) ans[n] = 'a';
printf("%s\n", ans);
return 0;
}
|
### Prompt
Construct a CPP code solution to the problem outlined:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
const int maxn = 100100;
char ch[maxn], ans[maxn];
int next[maxn];
int main() {
int n, len;
scanf("%d", &n);
for (int i = 0; i < maxn; i++) {
next[i] = i + 1;
ans[i] = -1;
}
int f = 1;
next[maxn - 1] = 0;
while (n--) {
scanf("%s", ch);
if (f == 1) {
f++;
len = strlen(ch);
}
next[len - 1] = -1;
ans[len] = 0;
int front = maxn - 1, t = next[maxn - 1];
while (t != -1) {
bool flag = false;
if (ans[t] != ch[t]) {
if (ans[t] == -1 && ch[t] != '?')
ans[t] = ch[t];
else if (ch[t] != '?') {
ans[t] = '?';
next[front] = next[t];
flag = true;
}
}
if (!flag) front = t;
t = next[t];
}
}
while (ans[++n] != 0)
if (ans[n] == -1) ans[n] = 'a';
printf("%s\n", ans);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
string a[100100 + 5];
int main() {
int n, i, j;
char p[100100 + 5];
while (cin >> n) {
memset(p, '0', sizeof(p));
for (i = 0; i < n; i++) cin >> a[i];
for (i = 0; i < a[0].size(); i++) {
int pos = 0;
for (j = 0; j < n; j++)
if (a[j][i] != '?') {
pos = 1;
break;
}
if (pos == 0) {
p[i] = 'a';
continue;
}
for (j = 0; j < n; j++)
if (p[i] != '?') {
if (p[i] == '0' && a[j][i] != '?')
p[i] = a[j][i];
else if (p[i] != a[j][i] && a[j][i] != '?')
p[i] = '?';
}
}
for (i = 0; i < a[0].size(); i++) printf("%c", p[i]);
printf("\n");
}
}
|
### Prompt
Construct a CPP code solution to the problem outlined:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string a[100100 + 5];
int main() {
int n, i, j;
char p[100100 + 5];
while (cin >> n) {
memset(p, '0', sizeof(p));
for (i = 0; i < n; i++) cin >> a[i];
for (i = 0; i < a[0].size(); i++) {
int pos = 0;
for (j = 0; j < n; j++)
if (a[j][i] != '?') {
pos = 1;
break;
}
if (pos == 0) {
p[i] = 'a';
continue;
}
for (j = 0; j < n; j++)
if (p[i] != '?') {
if (p[i] == '0' && a[j][i] != '?')
p[i] = a[j][i];
else if (p[i] != a[j][i] && a[j][i] != '?')
p[i] = '?';
}
}
for (i = 0; i < a[0].size(); i++) printf("%c", p[i]);
printf("\n");
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
bool visited[26];
int main() {
int n, i, j;
string p[100010];
set<char> let;
cin >> n;
for (i = 0; i < n; i++) {
cin >> p[i];
for (j = 0; j < p[i].size(); j++) {
if (p[i][j] != '?') visited[p[i][j] - 'a'] = 1;
}
}
char empt;
for (j = 0; j < 26; j++) {
if (!visited[j]) {
empt = j + 'a';
break;
}
}
string fin = "";
for (i = 0; i < p[0].size(); i++) {
let.clear();
for (j = 0; j < n; j++) {
if (p[j][i] != '?') let.insert(p[j][i]);
}
if (let.size() > 1)
fin += '?';
else if (let.size() == 1)
fin += *(let.begin());
else {
fin += empt;
}
}
cout << fin << endl;
return 0;
}
|
### Prompt
Generate a Cpp solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool visited[26];
int main() {
int n, i, j;
string p[100010];
set<char> let;
cin >> n;
for (i = 0; i < n; i++) {
cin >> p[i];
for (j = 0; j < p[i].size(); j++) {
if (p[i][j] != '?') visited[p[i][j] - 'a'] = 1;
}
}
char empt;
for (j = 0; j < 26; j++) {
if (!visited[j]) {
empt = j + 'a';
break;
}
}
string fin = "";
for (i = 0; i < p[0].size(); i++) {
let.clear();
for (j = 0; j < n; j++) {
if (p[j][i] != '?') let.insert(p[j][i]);
}
if (let.size() > 1)
fin += '?';
else if (let.size() == 1)
fin += *(let.begin());
else {
fin += empt;
}
}
cout << fin << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
char s1[N];
char s2[N];
bool f[N];
int main() {
int n;
scanf("%d", &n);
scanf("%s", s1);
for (int i = 1; i < n; ++i) {
scanf("%s", s2);
for (int j = 0; s2[j]; ++j) {
if (f[j]) continue;
if (s1[j] == '?') {
if (s2[j] != s1[j]) s1[j] = s2[j];
} else {
if (s1[j] != s2[j] && s2[j] != '?') {
s1[j] = '?';
f[j] = 1;
}
}
}
}
for (int i = 0; s1[i]; ++i)
if (s1[i] == '?' && !f[i]) s1[i] = 'x';
printf("%s\n", s1);
return 0;
}
|
### Prompt
Please formulate a CPP solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
char s1[N];
char s2[N];
bool f[N];
int main() {
int n;
scanf("%d", &n);
scanf("%s", s1);
for (int i = 1; i < n; ++i) {
scanf("%s", s2);
for (int j = 0; s2[j]; ++j) {
if (f[j]) continue;
if (s1[j] == '?') {
if (s2[j] != s1[j]) s1[j] = s2[j];
} else {
if (s1[j] != s2[j] && s2[j] != '?') {
s1[j] = '?';
f[j] = 1;
}
}
}
}
for (int i = 0; s1[i]; ++i)
if (s1[i] == '?' && !f[i]) s1[i] = 'x';
printf("%s\n", s1);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
void printfV(vector<int> V) {
for (int i = 0; i < V.size(); i++) printf("%d ", V[i]);
}
bool isprime(int N) {
for (int i = 2; i < sqrt(N); i++)
if (!(N % i)) return false;
return true;
}
struct SegTree {
int sz;
string ss;
vector<vector<int>> tree;
SegTree(string a) {
ss = a;
sz = ss.size();
tree.resize(2 * sz);
for (int i = 0; i < 2 * sz; i++) tree[i].resize(26);
for (int i = 0; i < sz; i++) tree[i + sz][ss[i] - 'a']++;
for (int i = sz - 1; i > 0; i--)
for (int j = 0; j < 2; j++)
for (int c = 0; c < 26; c++) tree[i][c] += tree[i * 2 + j][c];
}
void update(int index, char newValue) {
char old = ss[index - 1];
ss[index - 1] = newValue;
index += sz - 1;
while (index) {
tree[index][old - 'a']--;
tree[index][newValue - 'a']++;
index /= 2;
}
}
int query(int left, int right) {
bool answer[26] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
left += sz - 1;
right += sz - 1;
int TheRealAnswer = 0;
while (left < right) {
if (left % 2 != 2) {
for (int i = 0; i < 26; i++)
if (tree[left][i] || answer[i]) answer[i] = true;
left++;
}
if (right % 2 == 0) {
for (int i = 0; i < 26; i++)
if (tree[right][i] || answer[i]) answer[i] = true;
right--;
}
if (left >= right) break;
left /= 2;
right /= 2;
}
for (int i = 0; i < 26; i++)
if (tree[left][i] || tree[right][i]) answer[i] = true;
for (int i = 0; i < 26; i++)
if (answer[i]) TheRealAnswer++;
return TheRealAnswer;
}
int top() {
int TOP = 0;
for (int i = 0; i < 26; i++)
if (tree[1][i]) TOP++;
return TOP;
}
};
void solve(int casenumber) {
int n;
scanf("%d", &n);
string ss, answer;
n--;
cin >> answer;
while (n--) {
cin >> ss;
for (int i = 0; i < ss.size(); i++) {
if (ss[i] != '?' && answer[i] != '?' && answer[i] != ss[i])
answer[i] = 'X';
else if (answer[i] == '?')
answer[i] = ss[i];
}
}
for (int i = 0; i < answer.size(); i++)
if (answer[i] == '?')
answer[i] = 'f';
else if (answer[i] == 'X')
answer[i] = '?';
cout << answer << endl;
}
int main() {
int cases = 1;
for (int i = 0; i < cases; i++) solve(i + 1);
return 0;
}
|
### Prompt
Please provide a Cpp coded solution to the problem described below:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
void printfV(vector<int> V) {
for (int i = 0; i < V.size(); i++) printf("%d ", V[i]);
}
bool isprime(int N) {
for (int i = 2; i < sqrt(N); i++)
if (!(N % i)) return false;
return true;
}
struct SegTree {
int sz;
string ss;
vector<vector<int>> tree;
SegTree(string a) {
ss = a;
sz = ss.size();
tree.resize(2 * sz);
for (int i = 0; i < 2 * sz; i++) tree[i].resize(26);
for (int i = 0; i < sz; i++) tree[i + sz][ss[i] - 'a']++;
for (int i = sz - 1; i > 0; i--)
for (int j = 0; j < 2; j++)
for (int c = 0; c < 26; c++) tree[i][c] += tree[i * 2 + j][c];
}
void update(int index, char newValue) {
char old = ss[index - 1];
ss[index - 1] = newValue;
index += sz - 1;
while (index) {
tree[index][old - 'a']--;
tree[index][newValue - 'a']++;
index /= 2;
}
}
int query(int left, int right) {
bool answer[26] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
left += sz - 1;
right += sz - 1;
int TheRealAnswer = 0;
while (left < right) {
if (left % 2 != 2) {
for (int i = 0; i < 26; i++)
if (tree[left][i] || answer[i]) answer[i] = true;
left++;
}
if (right % 2 == 0) {
for (int i = 0; i < 26; i++)
if (tree[right][i] || answer[i]) answer[i] = true;
right--;
}
if (left >= right) break;
left /= 2;
right /= 2;
}
for (int i = 0; i < 26; i++)
if (tree[left][i] || tree[right][i]) answer[i] = true;
for (int i = 0; i < 26; i++)
if (answer[i]) TheRealAnswer++;
return TheRealAnswer;
}
int top() {
int TOP = 0;
for (int i = 0; i < 26; i++)
if (tree[1][i]) TOP++;
return TOP;
}
};
void solve(int casenumber) {
int n;
scanf("%d", &n);
string ss, answer;
n--;
cin >> answer;
while (n--) {
cin >> ss;
for (int i = 0; i < ss.size(); i++) {
if (ss[i] != '?' && answer[i] != '?' && answer[i] != ss[i])
answer[i] = 'X';
else if (answer[i] == '?')
answer[i] = ss[i];
}
}
for (int i = 0; i < answer.size(); i++)
if (answer[i] == '?')
answer[i] = 'f';
else if (answer[i] == 'X')
answer[i] = '?';
cout << answer << endl;
}
int main() {
int cases = 1;
for (int i = 0; i < cases; i++) solve(i + 1);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
char s[100005];
char liu[100005];
int main(void) {
int n, i, j, len;
while (scanf("%d", &n) == 1) {
memset(liu, '!', sizeof(liu));
for (i = 0; i < n; i++) {
cin >> s;
len = strlen(s);
for (j = 0; j < len; j++) {
if (s[j] == '?') {
continue;
} else {
if (liu[j] == '!') {
liu[j] = s[j];
} else {
if (liu[j] != s[j]) {
liu[j] = '?';
}
}
}
}
}
for (i = 0; i < len; i++) {
if (liu[i] == '!') {
liu[i] = 'a';
}
cout << liu[i];
}
cout << endl;
}
return 0;
}
|
### Prompt
Please provide a cpp coded solution to the problem described below:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
char s[100005];
char liu[100005];
int main(void) {
int n, i, j, len;
while (scanf("%d", &n) == 1) {
memset(liu, '!', sizeof(liu));
for (i = 0; i < n; i++) {
cin >> s;
len = strlen(s);
for (j = 0; j < len; j++) {
if (s[j] == '?') {
continue;
} else {
if (liu[j] == '!') {
liu[j] = s[j];
} else {
if (liu[j] != s[j]) {
liu[j] = '?';
}
}
}
}
}
for (i = 0; i < len; i++) {
if (liu[i] == '!') {
liu[i] = 'a';
}
cout << liu[i];
}
cout << endl;
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<string> pattern;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string t;
cin >> t;
pattern.push_back(t);
}
int flag = 0;
string output;
if (n == 1) {
for (int i = 0; i < pattern[0].size(); i++) {
if (pattern[0][i] == '?') {
pattern[0][i] = 'c';
}
}
cout << pattern[0];
return 0;
}
for (int i = 0; i < pattern[0].size(); i++) {
char tmp;
flag = 0;
for (int j = 0; j < n - 1; j++) {
if (pattern[j][i] != pattern[j + 1][i]) {
if (pattern[j][i] == '?') {
pattern[j][i] = pattern[j + 1][i];
tmp = pattern[j + 1][i];
flag = 3;
} else if (pattern[j + 1][i] == '?') {
pattern[j + 1][i] = pattern[j][i];
flag = 3;
tmp = pattern[j + 1][i];
} else {
flag = 1;
break;
}
} else if (pattern[j][i] != '?') {
flag = 3;
tmp = pattern[j][i];
}
}
if (flag == 1)
output.push_back('?');
else if (flag == 0)
output.push_back('c');
else if (flag == 3)
output.push_back(tmp);
}
cout << output;
}
|
### Prompt
Generate a CPP solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<string> pattern;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string t;
cin >> t;
pattern.push_back(t);
}
int flag = 0;
string output;
if (n == 1) {
for (int i = 0; i < pattern[0].size(); i++) {
if (pattern[0][i] == '?') {
pattern[0][i] = 'c';
}
}
cout << pattern[0];
return 0;
}
for (int i = 0; i < pattern[0].size(); i++) {
char tmp;
flag = 0;
for (int j = 0; j < n - 1; j++) {
if (pattern[j][i] != pattern[j + 1][i]) {
if (pattern[j][i] == '?') {
pattern[j][i] = pattern[j + 1][i];
tmp = pattern[j + 1][i];
flag = 3;
} else if (pattern[j + 1][i] == '?') {
pattern[j + 1][i] = pattern[j][i];
flag = 3;
tmp = pattern[j + 1][i];
} else {
flag = 1;
break;
}
} else if (pattern[j][i] != '?') {
flag = 3;
tmp = pattern[j][i];
}
}
if (flag == 1)
output.push_back('?');
else if (flag == 0)
output.push_back('c');
else if (flag == 3)
output.push_back(tmp);
}
cout << output;
}
```
|
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T sqr(T a) {
return a * a;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
for (int i = 0; i < v.size(); i++) cout << v[i] << " ";
cout << endl;
return cout;
}
void print() { cout << endl; }
template <typename T, typename... Ts>
void print(T x, Ts... xs) {
cout << x << " ";
print(xs...);
};
int val(char ch) {
if (ch == '?') return -1;
return ch - 'a';
}
int main() {
int n;
cin >> n;
vector<string> p(n, "");
for (int i = 0; i < n; i++) cin >> p[i];
int k = p[0].length();
vector<int> v(k, -1);
for (int i = 0; i < n; i++) {
for (int j = 0; j < k; j++) {
if (v[j] == -2) continue;
int l = val(p[i][j]);
if (l == -1) continue;
if (v[j] == -1 && l >= 0) {
v[j] = l;
} else {
if (v[j] != l) v[j] = -2;
}
}
}
string ret(k, 'x');
for (int i = 0; i < k; i++) {
if (v[i] == -1)
continue;
else if (v[i] == -2)
ret[i] = '?';
else
ret[i] = 'a' + v[i];
}
cout << ret;
}
|
### Prompt
Please formulate a cpp solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T sqr(T a) {
return a * a;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
for (int i = 0; i < v.size(); i++) cout << v[i] << " ";
cout << endl;
return cout;
}
void print() { cout << endl; }
template <typename T, typename... Ts>
void print(T x, Ts... xs) {
cout << x << " ";
print(xs...);
};
int val(char ch) {
if (ch == '?') return -1;
return ch - 'a';
}
int main() {
int n;
cin >> n;
vector<string> p(n, "");
for (int i = 0; i < n; i++) cin >> p[i];
int k = p[0].length();
vector<int> v(k, -1);
for (int i = 0; i < n; i++) {
for (int j = 0; j < k; j++) {
if (v[j] == -2) continue;
int l = val(p[i][j]);
if (l == -1) continue;
if (v[j] == -1 && l >= 0) {
v[j] = l;
} else {
if (v[j] != l) v[j] = -2;
}
}
}
string ret(k, 'x');
for (int i = 0; i < k; i++) {
if (v[i] == -1)
continue;
else if (v[i] == -2)
ret[i] = '?';
else
ret[i] = 'a' + v[i];
}
cout << ret;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<string> list;
int N;
cin >> N;
for (int i = 0; i < N; i++) {
string s;
cin >> s;
list.push_back(s);
}
int M = list[0].size();
string ret;
for (int i = 0; i < M; i++) {
set<char> S;
for (int j = 0; j < N; j++)
if (list[j][i] != '?') S.insert(list[j][i]);
if (S.empty())
ret += 'a';
else if (int((S).size()) == 1)
ret += *S.begin();
else
ret += '?';
}
cout << ret << endl;
}
|
### Prompt
Construct a CPP code solution to the problem outlined:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<string> list;
int N;
cin >> N;
for (int i = 0; i < N; i++) {
string s;
cin >> s;
list.push_back(s);
}
int M = list[0].size();
string ret;
for (int i = 0; i < M; i++) {
set<char> S;
for (int j = 0; j < N; j++)
if (list[j][i] != '?') S.insert(list[j][i]);
if (S.empty())
ret += 'a';
else if (int((S).size()) == 1)
ret += *S.begin();
else
ret += '?';
}
cout << ret << endl;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 5;
const long long mod = 1e9 + 7;
const long long N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
long long bp(long long pow, long long n) {
long long d = 1;
while (n) {
if (n % 2 == 1) d = (d * pow) % mod;
pow = (pow * pow) % mod;
n /= 2;
}
return d;
}
void solve() {
long long n;
cin >> n;
vector<string> v(n);
for (long long i = 0; i < n; i++) cin >> v[i];
string a = "";
a.append(v[0].size(), '?');
for (long long i = 0; i < v[0].size(); i++) {
map<char, long long> m;
long long ok = 1;
for (long long j = 0; j < n; j++) {
m[v[j][i]]++;
if (v[j][i] == '?') ok = 0;
}
if ((!ok && m.size() == 2) || (m.size() == 1 && ok)) {
for (auto it : m) {
if (it.first != '?') a[i] = it.first;
}
}
if (m.size() == 1 && ok == 0) {
for (long long j = 0; j < 26; j++) a[i] = char(j + 'a');
}
}
cout << a;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long t = 1;
while (t--) solve();
}
|
### Prompt
Create a solution in cpp for the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 5;
const long long mod = 1e9 + 7;
const long long N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
long long bp(long long pow, long long n) {
long long d = 1;
while (n) {
if (n % 2 == 1) d = (d * pow) % mod;
pow = (pow * pow) % mod;
n /= 2;
}
return d;
}
void solve() {
long long n;
cin >> n;
vector<string> v(n);
for (long long i = 0; i < n; i++) cin >> v[i];
string a = "";
a.append(v[0].size(), '?');
for (long long i = 0; i < v[0].size(); i++) {
map<char, long long> m;
long long ok = 1;
for (long long j = 0; j < n; j++) {
m[v[j][i]]++;
if (v[j][i] == '?') ok = 0;
}
if ((!ok && m.size() == 2) || (m.size() == 1 && ok)) {
for (auto it : m) {
if (it.first != '?') a[i] = it.first;
}
}
if (m.size() == 1 && ok == 0) {
for (long long j = 0; j < 26; j++) a[i] = char(j + 'a');
}
}
cout << a;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long t = 1;
while (t--) solve();
}
```
|
#include <bits/stdc++.h>
using namespace std;
char str[100001];
char mul[100001];
char res[100001];
int main() {
int n, len;
int i, j;
scanf("%d %s", &n, str);
len = strlen(str);
strcpy(res, str);
for (i = 1; i < n; i++) {
scanf("%s", str);
for (j = 0; j < len; j++) {
if (mul[j] == 1) continue;
if (str[j] != res[j]) {
if (str[j] == '?')
;
else if (res[j] == '?')
res[j] = str[j];
else {
mul[j] = 1;
res[j] = '?';
}
}
}
}
for (i = 0; i < len; i++) {
if (res[i] == '?' && mul[i] != 1)
printf("a");
else
printf("%c", res[i]);
}
printf("\n");
return 0;
}
|
### Prompt
In CPP, your task is to solve the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
char str[100001];
char mul[100001];
char res[100001];
int main() {
int n, len;
int i, j;
scanf("%d %s", &n, str);
len = strlen(str);
strcpy(res, str);
for (i = 1; i < n; i++) {
scanf("%s", str);
for (j = 0; j < len; j++) {
if (mul[j] == 1) continue;
if (str[j] != res[j]) {
if (str[j] == '?')
;
else if (res[j] == '?')
res[j] = str[j];
else {
mul[j] = 1;
res[j] = '?';
}
}
}
}
for (i = 0; i < len; i++) {
if (res[i] == '?' && mul[i] != 1)
printf("a");
else
printf("%c", res[i]);
}
printf("\n");
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n, len;
char s[100005];
string str[100005];
map<int, char> mapa;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> str[i];
len = str[1].length();
for (int i = 0; i < len; i++)
for (int j = 1; j <= n; j++) {
if (str[j][i] != '?') {
mapa[i] = str[j][i];
break;
}
if (j == n) mapa[i] = '?';
}
for (int i = 0; i < len; i++)
for (int j = 1; j <= n; j++) {
if (mapa[i] == '?') {
s[i] = 'a';
break;
}
if (str[j][i] != mapa[i] && str[j][i] != '?') {
s[i] = '?';
break;
}
if (j == n) s[i] = mapa[i];
}
cout << s << endl;
return 0;
}
|
### Prompt
Please provide a CPP coded solution to the problem described below:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, len;
char s[100005];
string str[100005];
map<int, char> mapa;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> str[i];
len = str[1].length();
for (int i = 0; i < len; i++)
for (int j = 1; j <= n; j++) {
if (str[j][i] != '?') {
mapa[i] = str[j][i];
break;
}
if (j == n) mapa[i] = '?';
}
for (int i = 0; i < len; i++)
for (int j = 1; j <= n; j++) {
if (mapa[i] == '?') {
s[i] = 'a';
break;
}
if (str[j][i] != mapa[i] && str[j][i] != '?') {
s[i] = '?';
break;
}
if (j == n) s[i] = mapa[i];
}
cout << s << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
int main() {
int n, len;
scanf("%d", &n);
char s[n][100000 / n + 10];
for (int i = 0; i < n; i++) {
scanf("%s", s[i]);
}
len = strlen(s[0]);
char ans[len + 1], mem;
int ch = 0;
for (int i = 0; i < len; i++) {
ch = 0;
for (int j = 0; j < n; j++) {
if (j == 0)
mem = s[j][i];
else {
if (mem != s[j][i] && mem != '?' && s[j][i] != '?') {
ch = 1;
ans[i] = '?';
break;
} else {
if (mem == '?') {
if (s[j][i] != '?') {
mem = s[j][i];
ans[i] = mem;
} else {
ans[i] = 'x';
}
} else {
if (s[j][i] == '?') {
if (mem == '?')
ans[i] = 'x';
else
ans[i] = mem;
} else {
ans[i] = mem;
}
}
}
}
}
}
ans[len] = '\0';
if (n == 1) {
for (int i = 0; i < len; i++) {
if (s[0][i] == '?')
printf("a");
else
printf("%c", s[0][i]);
}
} else {
printf("%s", ans);
}
return 0;
}
|
### Prompt
In cpp, your task is to solve the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
int main() {
int n, len;
scanf("%d", &n);
char s[n][100000 / n + 10];
for (int i = 0; i < n; i++) {
scanf("%s", s[i]);
}
len = strlen(s[0]);
char ans[len + 1], mem;
int ch = 0;
for (int i = 0; i < len; i++) {
ch = 0;
for (int j = 0; j < n; j++) {
if (j == 0)
mem = s[j][i];
else {
if (mem != s[j][i] && mem != '?' && s[j][i] != '?') {
ch = 1;
ans[i] = '?';
break;
} else {
if (mem == '?') {
if (s[j][i] != '?') {
mem = s[j][i];
ans[i] = mem;
} else {
ans[i] = 'x';
}
} else {
if (s[j][i] == '?') {
if (mem == '?')
ans[i] = 'x';
else
ans[i] = mem;
} else {
ans[i] = mem;
}
}
}
}
}
}
ans[len] = '\0';
if (n == 1) {
for (int i = 0; i < len; i++) {
if (s[0][i] == '?')
printf("a");
else
printf("%c", s[0][i]);
}
} else {
printf("%s", ans);
}
return 0;
}
```
|
#include <bits/stdc++.h>
int n, len;
char s[111111], ans[111111];
void upd(char &a, char b) {
if (b == '?') return;
if (a == '?')
a = b;
else if (a != b)
a = '#';
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s", s);
if (!i) {
len = strlen(s);
for (int j = 0; j < len; j++) ans[j] = '?';
}
for (int j = 0; j < len; j++) upd(ans[j], s[j]);
}
for (int i = 0; i < len; i++)
printf("%c", (ans[i] == '?') ? 'a' : ((ans[i] == '#') ? '?' : ans[i]));
printf("\n");
return 0;
}
|
### Prompt
Please provide a Cpp coded solution to the problem described below:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
int n, len;
char s[111111], ans[111111];
void upd(char &a, char b) {
if (b == '?') return;
if (a == '?')
a = b;
else if (a != b)
a = '#';
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s", s);
if (!i) {
len = strlen(s);
for (int j = 0; j < len; j++) ans[j] = '?';
}
for (int j = 0; j < len; j++) upd(ans[j], s[j]);
}
for (int i = 0; i < len; i++)
printf("%c", (ans[i] == '?') ? 'a' : ((ans[i] == '#') ? '?' : ans[i]));
printf("\n");
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
string arr[100005];
bool vis[100005];
struct cmp {
bool operator()(string a, string b) {
if (a.size() > b.size())
return false;
else if (a.size() < b.size())
return true;
else
return a < b;
}
};
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> arr[i];
sort(arr, arr + n, cmp());
reverse(arr, arr + n);
string ret = arr[0];
for (int i = 0; i < arr[0].size(); i++) {
for (int j = 0; j < n; j++) {
if (i >= arr[j].size())
break;
else if (ret[i] == '?' && !vis[i] && arr[j][i] != ret[i])
ret[i] = arr[j][i];
else if (arr[j][i] != ret[i] && arr[j][i] != '?')
ret[i] = '?', vis[i] = true;
}
}
for (int i = 0; i < ret.size(); i++)
if (vis[i] == false && ret[i] == '?') ret[i] = 'z';
cout << ret << endl;
}
|
### Prompt
Generate a Cpp solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string arr[100005];
bool vis[100005];
struct cmp {
bool operator()(string a, string b) {
if (a.size() > b.size())
return false;
else if (a.size() < b.size())
return true;
else
return a < b;
}
};
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> arr[i];
sort(arr, arr + n, cmp());
reverse(arr, arr + n);
string ret = arr[0];
for (int i = 0; i < arr[0].size(); i++) {
for (int j = 0; j < n; j++) {
if (i >= arr[j].size())
break;
else if (ret[i] == '?' && !vis[i] && arr[j][i] != ret[i])
ret[i] = arr[j][i];
else if (arr[j][i] != ret[i] && arr[j][i] != '?')
ret[i] = '?', vis[i] = true;
}
}
for (int i = 0; i < ret.size(); i++)
if (vis[i] == false && ret[i] == '?') ret[i] = 'z';
cout << ret << endl;
}
```
|
#include <bits/stdc++.h>
using namespace std;
char *tpl[100001];
bool fin[100001] = {};
char str[100001];
char res[100001];
int main() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> str;
tpl[i] = strdup(str);
}
int i = 0;
for (int col = n;; ++i) {
char t = '*';
for (int j = 0; j < n; ++j) {
if (fin[j]) continue;
if (!tpl[j][i]) {
fin[j] = true;
--col;
continue;
}
if (!((t == tpl[j][i]) || (tpl[j][i] == '?') || (t == '?'))) {
if (t == '*')
t = tpl[j][i];
else
t = '?';
}
}
if (!col) break;
if (t == '*') t = 'a';
res[i] = t;
}
res[i] = '\0';
cout << res;
return 0;
}
|
### Prompt
Create a solution in Cpp for the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
char *tpl[100001];
bool fin[100001] = {};
char str[100001];
char res[100001];
int main() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> str;
tpl[i] = strdup(str);
}
int i = 0;
for (int col = n;; ++i) {
char t = '*';
for (int j = 0; j < n; ++j) {
if (fin[j]) continue;
if (!tpl[j][i]) {
fin[j] = true;
--col;
continue;
}
if (!((t == tpl[j][i]) || (tpl[j][i] == '?') || (t == '?'))) {
if (t == '*')
t = tpl[j][i];
else
t = '?';
}
}
if (!col) break;
if (t == '*') t = 'a';
res[i] = t;
}
res[i] = '\0';
cout << res;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n, i, x, NN;
char s[100010], a[100010];
bool OK[1000001];
int main() {
scanf("%d\n", &NN);
gets(a);
n = strlen(a);
for (x = 2; x <= NN; ++x) {
gets(s);
for (i = 0; i < n; ++i)
if (s[i] != '?') {
if (s[i] == a[i])
continue;
else {
if (a[i] == '?') {
a[i] = s[i];
continue;
} else if (a[i] != s[i])
OK[i] = true;
}
}
}
for (i = 0; i < n; ++i) {
if (a[i] == '?')
printf("a");
else if (!OK[i])
printf("%c", a[i]);
else
printf("?");
}
return 0;
}
|
### Prompt
Construct a Cpp code solution to the problem outlined:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, i, x, NN;
char s[100010], a[100010];
bool OK[1000001];
int main() {
scanf("%d\n", &NN);
gets(a);
n = strlen(a);
for (x = 2; x <= NN; ++x) {
gets(s);
for (i = 0; i < n; ++i)
if (s[i] != '?') {
if (s[i] == a[i])
continue;
else {
if (a[i] == '?') {
a[i] = s[i];
continue;
} else if (a[i] != s[i])
OK[i] = true;
}
}
}
for (i = 0; i < n; ++i) {
if (a[i] == '?')
printf("a");
else if (!OK[i])
printf("%c", a[i]);
else
printf("?");
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
char a[100100], str[100100];
int l;
scanf("%s", a);
l = strlen(a);
for (int i = 0; i < n - 1; i += 1) {
scanf("%s", str);
for (int j = 0; j < l; j += 1) {
if (a[j] == '?')
a[j] = str[j];
else if (a[j] != str[j] && str[j] != '?')
a[j] = '*';
}
}
for (int i = 0; i < l; i += 1) {
if (a[i] == '*')
cout << "?";
else if (a[i] == '?')
cout << "x";
else
cout << a[i];
}
printf("\n");
return 0;
}
|
### Prompt
Your task is to create a Cpp solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
char a[100100], str[100100];
int l;
scanf("%s", a);
l = strlen(a);
for (int i = 0; i < n - 1; i += 1) {
scanf("%s", str);
for (int j = 0; j < l; j += 1) {
if (a[j] == '?')
a[j] = str[j];
else if (a[j] != str[j] && str[j] != '?')
a[j] = '*';
}
}
for (int i = 0; i < l; i += 1) {
if (a[i] == '*')
cout << "?";
else if (a[i] == '?')
cout << "x";
else
cout << a[i];
}
printf("\n");
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int vis[100010][30];
int num[100010][30];
char str[100010], ans[100010];
int main() {
int n, i, j, t, num, l;
scanf("%d", &n);
memset(vis, 0, sizeof(vis));
for (i = 1; i <= n; i++) {
scanf("%s", &str);
l = strlen(str);
for (j = 0; j < l; j++) {
if (str[j] == '?') continue;
vis[j][str[j] - 'a'] = 1;
}
}
for (i = 0; i < l; i++) {
num = 0;
for (j = 0; j < 26; j++) {
if (vis[i][j]) {
num++;
t = j;
}
}
if (num == 0)
ans[i] = 'a';
else if (num == 1)
ans[i] = 'a' + t;
else
ans[i] = '?';
}
ans[l] = '\0';
printf("%s\n", ans);
return 0;
}
|
### Prompt
Please formulate a Cpp solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int vis[100010][30];
int num[100010][30];
char str[100010], ans[100010];
int main() {
int n, i, j, t, num, l;
scanf("%d", &n);
memset(vis, 0, sizeof(vis));
for (i = 1; i <= n; i++) {
scanf("%s", &str);
l = strlen(str);
for (j = 0; j < l; j++) {
if (str[j] == '?') continue;
vis[j][str[j] - 'a'] = 1;
}
}
for (i = 0; i < l; i++) {
num = 0;
for (j = 0; j < 26; j++) {
if (vis[i][j]) {
num++;
t = j;
}
}
if (num == 0)
ans[i] = 'a';
else if (num == 1)
ans[i] = 'a' + t;
else
ans[i] = '?';
}
ans[l] = '\0';
printf("%s\n", ans);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int arr[102];
int main() {
int n;
cin >> n;
string res;
vector<string> v(n);
for (int i = 0; i < n; ++i) cin >> v[i];
for (int i = 0; i < v[0].size(); ++i) {
int x = 0;
bool zz = 0, e = 0;
char z;
if (isalpha(v[0][i])) {
z = v[0][i];
zz = 1;
} else
x++;
for (int j = 1; j < v.size(); ++j) {
if (v[j][i] == '?') {
x++;
} else if (isalpha(v[j][i]) && !zz) {
z = v[j][i];
zz = 1;
} else if (isalpha(v[j][i]) && zz) {
if (z != v[j][i]) {
e = 1;
break;
}
}
}
if (e)
res += '?';
else if (x == v.size())
res += 'a';
else
res += z;
}
cout << res << endl;
return 0;
}
|
### Prompt
Your task is to create a Cpp solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int arr[102];
int main() {
int n;
cin >> n;
string res;
vector<string> v(n);
for (int i = 0; i < n; ++i) cin >> v[i];
for (int i = 0; i < v[0].size(); ++i) {
int x = 0;
bool zz = 0, e = 0;
char z;
if (isalpha(v[0][i])) {
z = v[0][i];
zz = 1;
} else
x++;
for (int j = 1; j < v.size(); ++j) {
if (v[j][i] == '?') {
x++;
} else if (isalpha(v[j][i]) && !zz) {
z = v[j][i];
zz = 1;
} else if (isalpha(v[j][i]) && zz) {
if (z != v[j][i]) {
e = 1;
break;
}
}
}
if (e)
res += '?';
else if (x == v.size())
res += 'a';
else
res += z;
}
cout << res << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000 * 1000 * 1000 + 7;
const int INF = 2 * MOD;
int main() {
std::ios_base::sync_with_stdio(false);
int n;
cin >> n;
string pattern = "";
for (int i = 0; i < n; ++i) {
string t;
cin >> t;
if (pattern == "") {
pattern = t;
continue;
}
for (int i = 0; i < t.size(); ++i) {
if (t[i] != '?' && pattern[i] == '?') {
pattern[i] = t[i];
} else if (t[i] != '?' && t[i] != pattern[i]) {
pattern[i] = '.';
}
}
}
for (int i = 0; i < pattern.size(); ++i) {
if (pattern[i] == '.')
pattern[i] = '?';
else if (pattern[i] == '?')
pattern[i] = 'a';
}
cout << pattern << endl;
return 0;
}
|
### Prompt
Develop a solution in cpp to the problem described below:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000 * 1000 * 1000 + 7;
const int INF = 2 * MOD;
int main() {
std::ios_base::sync_with_stdio(false);
int n;
cin >> n;
string pattern = "";
for (int i = 0; i < n; ++i) {
string t;
cin >> t;
if (pattern == "") {
pattern = t;
continue;
}
for (int i = 0; i < t.size(); ++i) {
if (t[i] != '?' && pattern[i] == '?') {
pattern[i] = t[i];
} else if (t[i] != '?' && t[i] != pattern[i]) {
pattern[i] = '.';
}
}
}
for (int i = 0; i < pattern.size(); ++i) {
if (pattern[i] == '.')
pattern[i] = '?';
else if (pattern[i] == '?')
pattern[i] = 'a';
}
cout << pattern << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
char s[100010];
int ans[100010];
int main(int argc, const char* argv[]) {
long n;
scanf("%ld", &n);
scanf("%s", s);
long len = strlen(s);
for (long i = 0; i < len; i++) {
if (s[i] == '?') {
ans[i] = 0;
} else {
ans[i] = s[i];
}
}
for (long i = 1; i < n; i++) {
scanf("%s", s);
for (long j = 0; j < len; j++) {
if (ans[j] != s[j]) {
if (s[j] == '?') {
continue;
} else if (ans[j] == 0) {
ans[j] = s[j];
} else {
ans[j] = -1;
}
}
}
}
for (long i = 0; i < len; i++) {
if (ans[i] == 0) {
printf("a");
} else if (ans[i] == -1) {
printf("?");
} else {
printf("%c", ans[i]);
}
}
printf("\n");
return 0;
}
|
### Prompt
Please formulate a cpp solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
char s[100010];
int ans[100010];
int main(int argc, const char* argv[]) {
long n;
scanf("%ld", &n);
scanf("%s", s);
long len = strlen(s);
for (long i = 0; i < len; i++) {
if (s[i] == '?') {
ans[i] = 0;
} else {
ans[i] = s[i];
}
}
for (long i = 1; i < n; i++) {
scanf("%s", s);
for (long j = 0; j < len; j++) {
if (ans[j] != s[j]) {
if (s[j] == '?') {
continue;
} else if (ans[j] == 0) {
ans[j] = s[j];
} else {
ans[j] = -1;
}
}
}
}
for (long i = 0; i < len; i++) {
if (ans[i] == 0) {
printf("a");
} else if (ans[i] == -1) {
printf("?");
} else {
printf("%c", ans[i]);
}
}
printf("\n");
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
set<char> ltrs[100100];
int main() {
int n;
cin >> n;
int k;
string s;
for (int i = (0); i < ((n)); ++i) {
cin >> s;
int m = (int)(s).size();
for (int j = (0); j < ((m)); ++j)
if (s[j] != '?') ltrs[j].insert(s[j]);
}
k = (int)(s).size();
string res(k, '?');
for (int i = (0); i < ((k)); ++i) {
int m = (int)(ltrs[i]).size();
if (m == 0)
res[i] = 'x';
else if (m == 1)
res[i] = *ltrs[i].begin();
}
cout << res << endl;
return 0;
}
|
### Prompt
Your task is to create a CPP solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
set<char> ltrs[100100];
int main() {
int n;
cin >> n;
int k;
string s;
for (int i = (0); i < ((n)); ++i) {
cin >> s;
int m = (int)(s).size();
for (int j = (0); j < ((m)); ++j)
if (s[j] != '?') ltrs[j].insert(s[j]);
}
k = (int)(s).size();
string res(k, '?');
for (int i = (0); i < ((k)); ++i) {
int m = (int)(ltrs[i]).size();
if (m == 0)
res[i] = 'x';
else if (m == 1)
res[i] = *ltrs[i].begin();
}
cout << res << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
int main() {
static char s[100000], c[100000], bad[100000];
int n, m, i;
scanf("%d", &n);
memset(c, '#', sizeof c);
memset(bad, 0, sizeof bad);
while (n--) {
scanf("%s", s);
m = strlen(s);
for (i = 0; i < m; i++)
if (c[i] != '#' && s[i] != '?' && s[i] != c[i])
bad[i] = 1;
else if (c[i] == '#' && s[i] != '?')
c[i] = s[i];
}
for (i = 0; i < m; i++) printf("%c", bad[i] ? '?' : c[i] == '#' ? 'a' : c[i]);
printf("\n");
return 0;
}
|
### Prompt
Generate a cpp solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
int main() {
static char s[100000], c[100000], bad[100000];
int n, m, i;
scanf("%d", &n);
memset(c, '#', sizeof c);
memset(bad, 0, sizeof bad);
while (n--) {
scanf("%s", s);
m = strlen(s);
for (i = 0; i < m; i++)
if (c[i] != '#' && s[i] != '?' && s[i] != c[i])
bad[i] = 1;
else if (c[i] == '#' && s[i] != '?')
c[i] = s[i];
}
for (i = 0; i < m; i++) printf("%c", bad[i] ? '?' : c[i] == '#' ? 'a' : c[i]);
printf("\n");
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<string> s(n);
for (int i = 0; i < n; ++i) cin >> s[i];
int m = s[0].size();
string res(m, '?');
for (int j = 0; j < m; ++j) {
set<char> ss;
for (int i = 0; i < n; ++i)
if (isalpha(s[i][j])) ss.insert(s[i][j]);
res[j] = ss.empty() ? 'a' : ss.size() == 1 ? *ss.begin() : '?';
}
cout << res;
return 0;
}
|
### Prompt
Please provide a cpp coded solution to the problem described below:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<string> s(n);
for (int i = 0; i < n; ++i) cin >> s[i];
int m = s[0].size();
string res(m, '?');
for (int j = 0; j < m; ++j) {
set<char> ss;
for (int i = 0; i < n; ++i)
if (isalpha(s[i][j])) ss.insert(s[i][j]);
res[j] = ss.empty() ? 'a' : ss.size() == 1 ? *ss.begin() : '?';
}
cout << res;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tt;
tt = 1;
while (tt--) {
int n;
cin >> n;
string s;
int i;
vector<string> v;
for (i = 0; i < n; i++) {
cin >> s;
v.push_back(s);
}
set<char> st;
int l = s.length();
string str = "";
for (int j = 0; j < l; j++) {
st.clear();
char c;
for (i = 0; i < n; i++) {
if (v[i][j] != '?') st.insert(v[i][j]), c = v[i][j];
}
if (st.size() == 0)
str += 'a';
else if (st.size() == 1)
str += c;
else
str += '?';
}
cout << str << "\n";
}
}
|
### Prompt
Your task is to create a Cpp solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tt;
tt = 1;
while (tt--) {
int n;
cin >> n;
string s;
int i;
vector<string> v;
for (i = 0; i < n; i++) {
cin >> s;
v.push_back(s);
}
set<char> st;
int l = s.length();
string str = "";
for (int j = 0; j < l; j++) {
st.clear();
char c;
for (i = 0; i < n; i++) {
if (v[i][j] != '?') st.insert(v[i][j]), c = v[i][j];
}
if (st.size() == 0)
str += 'a';
else if (st.size() == 1)
str += c;
else
str += '?';
}
cout << str << "\n";
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100002;
int N, M, sol;
int v[MAX_N];
char s[MAX_N], m[MAX_N];
bool q[MAX_N];
int main() {
int K = 0;
scanf("%d", &N);
for (int i = 1; i <= N; ++i) {
scanf("%s", &s);
int len = strlen(s);
K = len;
for (int j = 0; j < len; ++j)
if (m[j] && m[j] != s[j] && s[j] != '?')
q[j] = 1;
else if (m[j] == 0 && s[j] != '?')
m[j] = s[j];
}
for (int i = 0; i < K; ++i) {
if (q[i])
printf("?");
else if (m[i])
printf("%c", m[i]);
else
printf("a");
}
printf("\n");
return 0;
}
|
### Prompt
Construct a CPP code solution to the problem outlined:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100002;
int N, M, sol;
int v[MAX_N];
char s[MAX_N], m[MAX_N];
bool q[MAX_N];
int main() {
int K = 0;
scanf("%d", &N);
for (int i = 1; i <= N; ++i) {
scanf("%s", &s);
int len = strlen(s);
K = len;
for (int j = 0; j < len; ++j)
if (m[j] && m[j] != s[j] && s[j] != '?')
q[j] = 1;
else if (m[j] == 0 && s[j] != '?')
m[j] = s[j];
}
for (int i = 0; i < K; ++i) {
if (q[i])
printf("?");
else if (m[i])
printf("%c", m[i]);
else
printf("a");
}
printf("\n");
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
string A[100005];
int N;
bool cnt[100005][70];
int s[100005][2];
int main() {
int x, i, j, k;
cin >> N;
for (i = 1; i <= N; i++) cin >> A[i];
for (i = 1; i <= N; i++) {
x = A[i].size();
for (j = 0; j < x; j++)
if (A[i][j] != '?') {
if (!cnt[j][A[i][j] - 'a']) s[j][0]++;
cnt[j][A[i][j] - 'a'] = 1;
s[j][1] = A[i][j] - 'a';
}
}
for (i = 0; i < x; i++) {
if (s[i][0] >= 2) {
cout << "?";
} else
printf("%c", s[i][1] + 'a');
}
return 0;
}
|
### Prompt
In CPP, your task is to solve the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string A[100005];
int N;
bool cnt[100005][70];
int s[100005][2];
int main() {
int x, i, j, k;
cin >> N;
for (i = 1; i <= N; i++) cin >> A[i];
for (i = 1; i <= N; i++) {
x = A[i].size();
for (j = 0; j < x; j++)
if (A[i][j] != '?') {
if (!cnt[j][A[i][j] - 'a']) s[j][0]++;
cnt[j][A[i][j] - 'a'] = 1;
s[j][1] = A[i][j] - 'a';
}
}
for (i = 0; i < x; i++) {
if (s[i][0] >= 2) {
cout << "?";
} else
printf("%c", s[i][1] + 'a');
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
template <typename T>
istream& operator>>(istream& I, vector<T>& v) {
for (auto& i : v) I >> i;
return I;
}
template <typename T>
ostream& operator<<(ostream& O, vector<T>& v) {
for (auto& i : v) O << i << ' ';
return O;
}
template <typename T>
istream& operator>>(istream& I, vector<vector<T>>& v) {
for (auto& i : v)
for (auto& x : i) I >> x;
return I;
}
template <typename T>
ostream& operator<<(ostream& O, vector<vector<T>>& v) {
for (auto& i : v) {
for (auto& x : i) O << x << ' ';
O << '\n';
}
return O;
}
template <typename T, typename U>
istream& operator>>(istream& I, pair<T, U>& p) {
I >> p.first >> p.second;
return I;
}
template <typename T, typename U>
ostream& operator<<(ostream& O, pair<T, U>& p) {
O << p.first << ' ' << p.second;
return O;
}
const int maxn = 1e6 + 3;
const int mod = 1e9 + 7;
void solve() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
int n;
cin >> n;
string s;
cin >> s;
for (int i = 1; i < n; i++) {
string t;
cin >> t;
for (int j = 0; j < s.length(); j++) {
if (s[j] == '?')
s[j] = t[j];
else if (s[j] != '?' && s[j] != t[j] && t[j] != '?')
s[j] = '*';
}
}
for (int i = 0; i < s.length(); i++) {
if (s[i] == '?') s[i] = 'x';
if (s[i] == '*') s[i] = '?';
}
cout << s << '\n';
}
int main() { solve(); }
|
### Prompt
Construct a Cpp code solution to the problem outlined:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
istream& operator>>(istream& I, vector<T>& v) {
for (auto& i : v) I >> i;
return I;
}
template <typename T>
ostream& operator<<(ostream& O, vector<T>& v) {
for (auto& i : v) O << i << ' ';
return O;
}
template <typename T>
istream& operator>>(istream& I, vector<vector<T>>& v) {
for (auto& i : v)
for (auto& x : i) I >> x;
return I;
}
template <typename T>
ostream& operator<<(ostream& O, vector<vector<T>>& v) {
for (auto& i : v) {
for (auto& x : i) O << x << ' ';
O << '\n';
}
return O;
}
template <typename T, typename U>
istream& operator>>(istream& I, pair<T, U>& p) {
I >> p.first >> p.second;
return I;
}
template <typename T, typename U>
ostream& operator<<(ostream& O, pair<T, U>& p) {
O << p.first << ' ' << p.second;
return O;
}
const int maxn = 1e6 + 3;
const int mod = 1e9 + 7;
void solve() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
int n;
cin >> n;
string s;
cin >> s;
for (int i = 1; i < n; i++) {
string t;
cin >> t;
for (int j = 0; j < s.length(); j++) {
if (s[j] == '?')
s[j] = t[j];
else if (s[j] != '?' && s[j] != t[j] && t[j] != '?')
s[j] = '*';
}
}
for (int i = 0; i < s.length(); i++) {
if (s[i] == '?') s[i] = 'x';
if (s[i] == '*') s[i] = '?';
}
cout << s << '\n';
}
int main() { solve(); }
```
|
#include <bits/stdc++.h>
using namespace std;
char m[1000000];
int main() {
int t, i, j;
string s;
cin >> t;
cin >> s;
int l = s.length();
for (i = 0; i < l; i++) m[i] = s[i];
for (i = 1; i < t; i++) {
cin >> s;
for (j = 0; j < l; j++) {
if (m[j] == '?') m[j] = s[j];
if (m[j] != s[j] && s[j] != '?') m[j] = '!';
}
}
for (i = 0; i < l; i++) {
if (m[i] == '?')
cout << 'x';
else if (m[i] == '!')
cout << '?';
else
cout << m[i];
}
return 0;
}
|
### Prompt
Your challenge is to write a Cpp solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
char m[1000000];
int main() {
int t, i, j;
string s;
cin >> t;
cin >> s;
int l = s.length();
for (i = 0; i < l; i++) m[i] = s[i];
for (i = 1; i < t; i++) {
cin >> s;
for (j = 0; j < l; j++) {
if (m[j] == '?') m[j] = s[j];
if (m[j] != s[j] && s[j] != '?') m[j] = '!';
}
}
for (i = 0; i < l; i++) {
if (m[i] == '?')
cout << 'x';
else if (m[i] == '!')
cout << '?';
else
cout << m[i];
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a;
string b[100010], puz;
bool c = 0;
cin >> a;
for (int i = 0; i < a; i++) cin >> b[i];
puz = b[0];
for (int i = 1; i < a; i++) {
for (int j = 0; j < puz.size(); j++) {
if ((puz[j] != '?') & (b[i][j] != '?') & (puz[j] != b[i][j])) {
puz[j] = '#';
} else if ((puz[j] == '?') & (b[i][j] != '?'))
puz[j] = b[i][j];
}
}
for (int i = 0; i < puz.size(); i++)
if (puz[i] == '?')
puz[i] = 'x';
else if (puz[i] == '#')
puz[i] = '?';
cout << puz;
return 0;
}
|
### Prompt
In cpp, your task is to solve the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int a;
string b[100010], puz;
bool c = 0;
cin >> a;
for (int i = 0; i < a; i++) cin >> b[i];
puz = b[0];
for (int i = 1; i < a; i++) {
for (int j = 0; j < puz.size(); j++) {
if ((puz[j] != '?') & (b[i][j] != '?') & (puz[j] != b[i][j])) {
puz[j] = '#';
} else if ((puz[j] == '?') & (b[i][j] != '?'))
puz[j] = b[i][j];
}
}
for (int i = 0; i < puz.size(); i++)
if (puz[i] == '?')
puz[i] = 'x';
else if (puz[i] == '#')
puz[i] = '?';
cout << puz;
return 0;
}
```
|
#include <bits/stdc++.h>
void quit();
using namespace std;
const long double PI = acos(-1);
const long double EPS = 1e-10;
double __t;
int n;
string s;
char c[100100];
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s;
for (int j = 0; j < s.size(); j++)
if (s[j] != '?') {
if (c[j] == 0)
c[j] = s[j];
else if (c[j] != s[j])
c[j] = '?';
}
}
for (int i = 0; i < s.size(); i++) {
if (c[i] == 0)
cout << 'a';
else
cout << c[i];
}
quit();
}
void quit() { exit(0); }
|
### Prompt
Create a solution in cpp for the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
void quit();
using namespace std;
const long double PI = acos(-1);
const long double EPS = 1e-10;
double __t;
int n;
string s;
char c[100100];
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s;
for (int j = 0; j < s.size(); j++)
if (s[j] != '?') {
if (c[j] == 0)
c[j] = s[j];
else if (c[j] != s[j])
c[j] = '?';
}
}
for (int i = 0; i < s.size(); i++) {
if (c[i] == 0)
cout << 'a';
else
cout << c[i];
}
quit();
}
void quit() { exit(0); }
```
|
#include <bits/stdc++.h>
using namespace std;
void problem_solver() {
int n;
string ans;
cin >> n;
int l;
vector<string> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
l = a[0].length();
for (int i = 0; i < l; i++) {
bool ok = false;
set<char> st;
for (int j = 0; j < n; j++) {
if (a[j][i] != '?') {
st.insert(a[j][i]);
ok = true;
}
}
if (ok) {
auto itr = st.begin();
if (st.size() > 1) {
ans += '?';
} else
ans += *itr;
} else
ans += 'x';
}
cout << ans;
}
int main() { problem_solver(); }
|
### Prompt
Develop a solution in cpp to the problem described below:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
void problem_solver() {
int n;
string ans;
cin >> n;
int l;
vector<string> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
l = a[0].length();
for (int i = 0; i < l; i++) {
bool ok = false;
set<char> st;
for (int j = 0; j < n; j++) {
if (a[j][i] != '?') {
st.insert(a[j][i]);
ok = true;
}
}
if (ok) {
auto itr = st.begin();
if (st.size() > 1) {
ans += '?';
} else
ans += *itr;
} else
ans += 'x';
}
cout << ans;
}
int main() { problem_solver(); }
```
|
#include <bits/stdc++.h>
using namespace std;
int n, m;
char a[101001], b[101001];
int main() {
scanf("%d", &n);
for (int i = (0); i < (n); i++) {
scanf("%s", a);
m = strlen(a);
for (int i = (0); i < (m); i++) {
if (a[i] == '?')
continue;
else if (a[i] != b[i]) {
if (!b[i])
b[i] = a[i];
else
b[i] = '?';
}
}
}
for (int i = (0); i < (m); i++)
if (!b[i]) b[i] = 'a';
puts(b);
return 0;
}
|
### Prompt
Create a solution in cpp for the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m;
char a[101001], b[101001];
int main() {
scanf("%d", &n);
for (int i = (0); i < (n); i++) {
scanf("%s", a);
m = strlen(a);
for (int i = (0); i < (m); i++) {
if (a[i] == '?')
continue;
else if (a[i] != b[i]) {
if (!b[i])
b[i] = a[i];
else
b[i] = '?';
}
}
}
for (int i = (0); i < (m); i++)
if (!b[i]) b[i] = 'a';
puts(b);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<string> strs(n);
for (string& s : strs) {
cin >> s;
}
for (int i = 0; i < strs[0].length(); i++) {
char found = 0;
for (string& s : strs) {
if (s[i] != '?') {
if (found == 0 || found == s[i]) {
found = s[i];
} else {
cout << '?';
goto tonne;
}
}
}
if (found != 0)
cout << found;
else
cout << "a";
tonne:;
}
cout << endl;
return 0;
}
|
### Prompt
Generate a cpp solution to the following problem:
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?
Input
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.
Output
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.
Examples
Input
2
?ab
??b
Output
xab
Input
2
a
b
Output
?
Input
1
?a?b
Output
cacb
Note
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.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<string> strs(n);
for (string& s : strs) {
cin >> s;
}
for (int i = 0; i < strs[0].length(); i++) {
char found = 0;
for (string& s : strs) {
if (s[i] != '?') {
if (found == 0 || found == s[i]) {
found = s[i];
} else {
cout << '?';
goto tonne;
}
}
}
if (found != 0)
cout << found;
else
cout << "a";
tonne:;
}
cout << endl;
return 0;
}
```
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.