Cod sursă (job #796419)

Utilizator avatar mariusharabari Marius Harabari mariusharabari IP ascuns
Problemă Bizar (clasele 9-10) Compilator cpp-32 | 1,51 kb
Rundă Arhiva de probleme Status evaluat
Dată 21 nov. 2024 14:59:42 Scor 70
#include <bits/stdc++.h>
using namespace std;

ifstream fin("bizar.in");
ofstream fout("bizar.out");

int n, i, j, ok;
char t[100005];
int v[500001];

int bizar(int a, int s){
    int k=s;
    cout<<a<<endl;
    int nx=0;

    while(t[i]==' ') i++;

    if(t[i]=='('){
        k++;
        i++;
        v[k]=bizar(nx, k);
    }

    while(t[i]!=')'){
        ok=1;
        nx=0;
        while(t[i]>='0'&&t[i]<='9'){
            nx*=10;
            nx+=t[i]-'0';
            i++;
        }
        //cout<<nx;

        while(t[i]==' ') i++;

        //cout<<t[i];
        if(t[i]==','){
            k++;
            v[k]=nx;
            cout<<k<<' '<<nx<<endl;
            i++;
        }
        else if(t[i]=='('){
            k++;
            i++;
            v[k]=bizar(nx, k);
            cout<<k<<' '<<v[k]<<endl;
            ok=0;
        }

        while(t[i]==' ') i++;

        if(t[i]==',')
            i++;
        while(t[i]==' ') i++;
    }
    if(ok){
        k++;
        v[k]=nx;
        cout<<k<<' '<<nx<<endl;
    }

    i++;
    cout<<a%(k-s)<<endl;
    if(a%(k-s)==0) return v[k];
    return v[s+a%(k-s)];
}
int main(){
    fin.getline(t, 100005);
    int x=0;
    n=strlen(t);
    while(x==0||(t[i]>='0'&&t[i]<='9')){
        if(t[i]>'0'&&t[i]<'9'){
            x*=10;
            x+=t[i]-'0';
        }
        i++;
    }
    while(t[i]!='(') i++;
    while(i<n){
            i++;
        x=bizar(x, 0);

    }
    fout<<x;
    return 0;
}