Cod sursă (job #339437)

Utilizator avatar PredaBoss Preda Andrei PredaBoss IP ascuns
Problemă Bizar (clasele 9-10) Compilator cpp | 1,27 kb
Rundă Arhiva de probleme Status evaluat
Dată 13 ian. 2018 21:39:33 Scor 70
#include <bits/stdc++.h>
using namespace std;
ifstream fin("bizar.in");
ofstream fout("bizar.out");
int i,k[10000],j,v[10000][10000],p[10000];
char a[100000];
int termen()
{
    int n=0;
    while(a[i]-'0'>=0 && a[i]-'0'<=9)
    {
        n=n*10+a[i]-'0';
        i++;
    }
    return n;
}
int calcul()
{
    cout<<i<<" ";
    while(a[i]!='(')
            i++;
    i++;
    while(a[i]!='\0' && a[i]!=')')
    {
        if(a[i]-'0'>=0 && a[i]-'0'<=9)
        {
            p[j]++;
            v[j][p[j]]=termen();
        }
        else
        {
            if(a[i]=='(')
            {
                j++;
                k[j]=v[j-1][p[j-1]];
                p[j]=0;
                v[j-1][p[j-1]]=calcul();
                j--;
            }
            else
            {
                i++;
            }
        }
    }
    if(a[i]!='\0'){
            i++;
        while('0'-a[i]==16 && a[i]!='\0')
            i++;
    }
    if(a[i]=='(')
    {
        v[j][0]=v[j][p[j]];
        k[j]=v[j][k[j]%p[j]];
        p[j]=0;
        return calcul();
    }
    else
    {
        v[j][0]=v[j][p[j]];
        return v[j][k[j]%p[j]];
    }
}
int main()
{
    fin.get(a,100000);
    k[0]=termen();
    fout<<calcul();
    return 0;
}