Cod sursă (job #817536)

Utilizator avatar mihaigeorgescu Georgescu Mihai mihaigeorgescu IP ascuns
Problemă Bizar (clasele 9-10) Compilator cpp-32 | 1.12 kb
Rundă antrenament Status evaluat
Dată 2 apr. 2025 09:45:11 Scor 100
#include <fstream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
ifstream fcin("bizar.in");
ofstream fout("bizar.out");
string s;
int i,vf,stv[100000];
vector <int> v;
int main()
{
    getline(fcin, s);
    while(i<s.size())
    {
        if(s[i]=='(')
        {
            stv[++vf]=-1;
        }
        else
        {
            if(isdigit(s[i]))
            {
                int val=0;
                while(i<s.size() && isdigit(s[i])) val=val*10+s[i]-48, i++;i--;
                stv[++vf]=val;
            }
            else
            {
                if(s[i]==')')
                {
                    v.clear();
                    while(stv[vf]!=-1)
                    {
                        v.push_back(stv[vf]);
                        vf--;
                    }
                    reverse(v.begin(), v.end());
                    vf--;
                    int k=stv[vf]-1;
                    vf--;
                    stv[++vf]=v[k%(v.size())];
                }
            }
        }
        i++;
    }
    fout<<stv[1];
    return 0;
}