-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathround1A2020_pattern_matching.cpp
More file actions
66 lines (56 loc) · 1.3 KB
/
Copy pathround1A2020_pattern_matching.cpp
File metadata and controls
66 lines (56 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
using vld = vector<ld>;
using vpii = vector<pii>;
using vpil = vector<pil>;
using vpli = vector<pli>;
using vpll = vector<pll>;
#define x first
#define y second
void solve(){
int n;
cin >> n;
vector<string> v;
for(int i = 0; i < n; i++){
string s;
cin >> s;
v.push_back(s);
}
string pf, mid, sf;
for(int i = 0; i < n; i++){
int l = v[i].length();
int j, k, c;
for(j = 0; j < l; j++){
if(v[i][j] == '*') break;
if(pf.length() == j) pf.push_back(v[i][j]);
if(pf[j] != v[i][j]){ cout << "*\n"; return; }
}
for(k = l - 1, c = 0; k > 0; k--, c++){
if(v[i][k] == '*') break;
if(sf.length() == c) sf.push_back(v[i][k]);
if(sf[c] != v[i][k]){ cout << "*\n"; return; }
}
for(; j < k; j++) if(v[i][j] != '*') mid.push_back(v[i][j]);
}
reverse(sf.begin(), sf.end());
cout << pf << mid << sf << '\n';
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
for(int i = 1; i <= t; i++){
cout << "Case #" << i << ": ";
solve();
}
return 0;
}