-
Notifications
You must be signed in to change notification settings - Fork 0
/
uva416.cpp
79 lines (62 loc) · 1.46 KB
/
uva416.cpp
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
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
const vector<string> representation = {
"YYYYYYN",
"NYYNNNN",
"YYNYYNY",
"YYYYNNY",
"NYYNNYY",
"YNYYNYY",
"YNYYYYY",
"YYYNNNN",
"YYYYYYY",
"YYYYNYY"
};
bool burnt[10];
bool match(string sequence, int number){
for(int i = 0; i < sequence.size(); i++){
if(sequence[i] == 'Y' && burnt[i]){
return false;
}
if(representation[number][i] == sequence[i]){
continue;
}else if(sequence[i] == 'Y'){
return false;
}else if(sequence[i] == 'N'){
burnt[i] = true;
}
}
return true;
}
bool countMatch(vector<string>& sequences, int start){
int count = sequences.size();
memset(burnt, 0, sizeof(burnt));
for(int i = start; i > start - count; i--){
if(!match(sequences[start - i], i)){
return false;
}
}
return true;
}
bool isCountingDown(vector<string>& sequences){
for(int i = 9; i >= sequences.size() - 1; i--){
if(countMatch(sequences, i)){
return true;
}
}
return false;
}
int main(){
int n;
while(cin>>n && n != 0){
vector<string> sequences;
string line;
for(int i = 0; i < n; i++){
cin>>line;
sequences.push_back(line);
}
cout<<(isCountingDown(sequences) ? "MATCH" : "MISMATCH")<<endl;
}
}