Pagini recente »
Borderou de evaluare (job #251014)
|
2016-04-19-test-6
|
pre_oni_clasa-a_5-6-7
|
Istoria paginii runda/2k
|
Cod sursă (job #435042)
Cod sursă (job
#435042)
#include <iostream>
#include <cstring>
#include <fstream>
using namespace std;
ifstream fin("bizar.in");
ofstream fout("bizar.out");
char s[100010];
int st[100010], lg;
int top;
void Stiva()
{
int i;
fin.getline(s,100005);
lg = strlen(s);
for(i = 0; i < lg; i++)
if(s[i] == '(')
st[++top] = -1;
else if(s[i] >= '0' && s[i] <= '9')
{
int x = 0;
while(s[i] >= '0' && s[i] <= '9')
{
x = x * 10 + (s[i] - '0');
i++;
}
i--;
st[++top] = x;
}
else if(s[i] == ')')
{
int x = 0, k;
k = top;
while(st[top] != -1)
top--, x++;
top--;
if(st[top] < k - top - 1)
{
st[top] = st[top + (k - top - 1) - 1];
//cout << k - top - 1 << "\n";
}
else if(st[top] % (k - top - 1) != 0) st[top] = st[top + (st[top] % (k - top - 1)) + 1 ];
else st[top] = st[top + (k - top) ];
//cout << st[top] << "\n";
}
}
int main()
{
Stiva();
fout << st[top];
return 0;
}