Pagini recente »
Istoria paginii runda/2014-12-02-test-5/clasament
|
Atașamentele paginii Clasament tema08-seniori-2014-2015
|
Istoria paginii runda/vaslui_cls9_15.02/clasament
|
Istoria paginii utilizator/vladpandelescu2
|
Cod sursă (job #435175)
Cod sursă (job
#435175)
#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 ('0' <= s[i] && s[i] <= '9')
{
x = x * 10 + s[i] - '0';
i++;
}
i--;
st[++top] = x;
}
else if(s[i] == ')')
{
int x = 0, k, y;
k = top;
while(st[k] != -1)
k--, x++;
y = st[k-1];
y = y % x;
if(y % x == 0) y = x;
st[k-1] = st[k + y];
top = --k;
}
}
int main()
{
Stiva();
fout << st[1];
return 0;
}