Pagini recente » Cod sursa (job #1067637) | Cod sursa (job #3156598) | Cod sursa (job #2349514) | Cod sursa (job #2020206) | Cod sursa (job #1994772)
#include <iostream>
#include <stack>
#ifndef ONLINE_JUDGE
#include <fstream>
#include <conio.h>
#endif
using namespace std;
int n;
char s[15];
deque<int> st;
int changes = 0;
int main()
{
#ifndef ONLINE_JUDGE
ifstream cin("test.in");
#endif
#ifdef ONLINE_JUDGE
ios_base::sync_with_stdio(false);
#endif
cin >> n;
int m = 2 * n;
int top = 1;
cin.get();
for (int i = 1;i <= m;i++)
{
cin.getline(s, 16);
if (s[0] == 'a')
{
int x = 0;
for (int j = 4;s[j];j++)
x = x * 10 + s[j] - '0';
st.push_back(x);
}
if (s[0] == 'r')
{
if (st.back() == top)
{
st.pop_back();
top++;
}
else
{
while (st.back() != top && !st.empty())
{
changes++;
st.push_front(st.back());
st.pop_back();
}
top++;
st.pop_back();
}
}
}
// pica pe exemplul 5, 3, 2, 1, 4
// trebuie sa fac cu un vector din ala jmecher
cout << changes;
#ifndef ONLINE_JUDGE
cin.close();
_getch();
#endif
return 0;
}