Cod sursă (job #435175)

Utilizator avatar iustin948 Homoranu Iustin iustin948 IP ascuns
Problemă Bizar (clasele 9-10) Compilator cpp | 0,99 kb
Rundă Arhiva de probleme Status evaluat
Dată 13 feb. 2019 20:55:12 Scor 100
#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;
}