Pagini recente »
Cod sursă (job #434686)
Cod sursă (job
#434686)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("bizar.in");
ofstream fout("bizar.out");
char s[100005];
int st[100005], top;
int cifra(char ch)
{
if('0' <= ch && ch <= '9')
return 1;
return 0;
}
int main()
{
int i, j, cnt = 0, rest, x;
fin.getline(s, 100005);
for(i = 0; s[i];)
{
if(cifra(s[i]))
{
int x = 0;
while(cifra(s[i]))
{
x = x * 10 + (s[i] - '0');
i++;
}
st[++top] = x;
}
if(s[i] == '(')
st[++top] = -1;
if(s[i] == ')')
{
j = top;
while(st[j] != -1)
{
j--;
cnt++;
}
rest = st[j - 1] % cnt;
if(rest == 0)
x = st[j + cnt];
else
x = st[j + rest];
top = j - 1;
st[top] = x;
cnt = 0;
i++;
}
else i++;
}
fout << st[1];
fin.close();
fout.close();
return 0;
}