File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ #include < iostream>
2+ #include < vector>
3+
4+ using namespace std ;
5+
6+ int main () {
7+
8+ int n, start = 0 , cont = 0 ;
9+ cin >> n;
10+ vector<vector<char > >v;
11+ vector<char > aux1 (4 , ' ' );
12+
13+ v.push_back ({' F' , ' A' , ' C' , ' E' });
14+
15+ while (n--) {
16+ for (int j = 0 ; j < 4 ; j++) {
17+ cin >> aux1[j];
18+ }
19+ int qtd = 0 ;
20+ // check if it matches
21+ vector<char > aux2 = v[(int )v.size () - 1 ]; // getting last element of the vector
22+ for (int j = 0 , h = 3 ; j < 4 ; j++, h--) {
23+ if (aux1[j] == aux2[h]) { // h allows to run backwards
24+ qtd++; // count number of matches between last added word and current one
25+ }
26+ }
27+
28+ // if it's equal to 4, then, pop last added to vector and count + 1
29+ if (qtd == 4 ) {
30+ v.pop_back (); // pop last word cause it was a match
31+ if (v.empty ()) { // check if it's empty, because if that's the case, it must be added the word face again
32+ v.push_back ({' F' , ' A' , ' C' , ' E' }); // add again because it's empty
33+ }
34+ cont++; // count number of person who receives the award
35+ } else {
36+ // need to add new word
37+ v.push_back (aux1); // because the word added is not equal to the added before (in backward order)
38+ }
39+ }
40+
41+ cout << cont << endl;
42+
43+
44+ return 0 ;
45+ }
You can’t perform that action at this time.
0 commit comments