[URI ONLINE JUDGE] – 2061 – Closing Tabs

Péricles has an unique interest in history. With his up-to-date internet browser chromed fox, he wandered in the most obscure sites about ancient Greek mythology.

By some type of cosmic irony, Péricles’ browser was infected by a malware with a peculiar characteristic: every time Péricles closed a tab in his browser, another two opened! However, when Péricles clicked one of the ads (all tabs were infested with ads), the tab crashed, and no other tabs were opened.

Your taks is to compute the final number of tabs of Péricles’s browser, knowing the initial number of tabs and the actions taken by Péricles. There are two possible actions: fechou (when Péricles closed a tab) and clicou (when Péricles clicked on an ad).

Input

The input is initiated by a line containing two integer numbers, N e M (0 < N, M < 500), representing the initial number of tabs and the number of actions performed by Péricles. Each subsequent line contains an action (fechou or clicou). Naturally, the current number of tabs is always greater of equal to zero.

Output

The output must consist of a line containing the final number of tabs.

Input Sample Output Sample
3 5
fechou
fechou
clicou
clicou
clicou
2

 

solution:

 

<br /> 

#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
int n, m;
cin >> n >> m;
for(int i = 0; i < m; i++) {
string s;
cin >> s;
if(s == "fechou") n++;
else n--;
}
cout << n << endl;

return 0;
}

 

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