Pagini recente »
Cod sursă (job #118072)
|
Monitorul de evaluare
|
Cod sursă (job #128399)
Cod sursă (job
#128399)
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
#define NMAX 110000
int p,N;
char str[NMAX];
int expresie(int);
int main()
{
freopen("bizar.in","r",stdin);
freopen("bizar.out","w",stdout);
gets(str);
N=strlen(str);
printf("%d\n",expresie(1));
return 0;
}
int expresie (int x)
{
vector < int > e;
while (p<N && str[p]!=')')
{
if (str[p]=='(')
{
int t=e[e.size()-1];
e.pop_back();
++p;
e.push_back(expresie(t));
}
if (str[p]==',' || str[p]==' ')
{
++p;
continue;
}
if ('0'<=str[p] && str[p]<='9')
{
int n=0;
while ('0'<=str[p] && str[p]<='9')
{
n=n*10+str[p]-'0';
++p;
}
e.push_back(n);
}
}
x=x%e.size();
++p;
if (x==0) return e[e.size()-1];
else return e[x-1];
}