[URI ONLINE JUDGE] – 1944 – FACE 2015 FREE GIFT

Link: https://www.urionlinejudge.com.br/judge/en/problems/view/1944

In this year of 2015, FACE is supporting the third edition of the Programming Marathon, but, at this time, organization’s staff is requesting your help to create a lottery system by using the FACE letters. As this fair uses a differentiated and cheerful proposal, each participant who enters into the fair receives 4 letters, each of them in a different color and in the form of a wooden block, as shown in Figure 1, and they must insert them in a panel. If, by the entering time, the 4 letters create the opposite of the 4 last letters, this visitor will receive the free gift.

Brinde_FACE

Figure 1 – FACE entrance on the panel followed by ACEF.

For example: suppose there have already been three visitors who entered into the fair and the letters’ distribution remained as follows: F A C E E C F A A C F E A C E F. See that the panel, for being empty, the letters F A C E were inserted in order to start the process, now, as the fourth visitor enters, he has inserted the letters F E C A and, with it, they will receive the free gift as it got the opposite of A C E F. After this situation, the letters must remain F A C E E C F A A C F E. Another important fact is that, the free gifts’ distribution occurs in a certain period with a sample of a selected visitors number. REMENBER, always when the panel remains empty it is automatically inserted the letters F A C E.

Input

The input contains several test cases. The first line of a test case contains an integer N (1 ≤ N ≤ 100), representing the number of visitors who will receive the letters. In each subsequent line it must be informed the 4 letters combination separated by space that the visitor wishes to insert on the panel. The stop is determined by N equals to 0.

Output

For each of group of visitors, it must be informed how many of them will receive free gifts.

Input Samples Output Samples
4

E C F A

A C E F

F E C A

A F C E

2
3

E A C F

A F C E

E F C A

0
6

E C A F

E C A F

E C A F

E C A F

E C A F

E C A F

6

solution:

#include <bits/stdc++.h>
using namespace std;
stack v;

int main()
{
int n;

char c;
string aux;

int ans;

while (cin >> n)
{
ans = 0;
v.push("FACE");
for (int i = 0 ; i < n ; ++i)
{
aux.clear();
for (int j = 0 ; j < 4 ; ++j) { cin >> c;
aux.push_back(c);
}
string aux2 = aux;
reverse(aux2.begin(), aux2.end());

if (v.top() == aux2)
{
++ans;
v.pop();
if (v.size() == 0) v.push("FACE");
}
else
v.push(aux);
}
cout << ans << '\n';
while (!v.empty()) v.pop();
}
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s