Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f80807b

Browse files
it was added a new problem solved on uri plataform, the id is 1944
this problem was solved using vector from c++
1 parent cb323bc commit f80807b

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

‎Online Judges/URI/1944.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /