Cod sursă (job #158033)

Utilizator avatar AlexIonPopescu Popescu Ion Alexandru AlexIonPopescu IP ascuns
Problemă Bizar (clasele 9-10) Compilator cpp | 0,97 kb
Rundă Arhiva de probleme Status evaluat
Dată 5 oct. 2015 15:02:47 Scor 100
#include<fstream>
#include<string.h>
using namespace std;
ifstream fin("bizar.in");
ofstream fout("bizar.out");
int n, i, j, l, m, v[100005];
char s[100005];
void eliminare(){
    while(s[i]==' ')
        i++;
}
int procent(int x, int y){
    int z=x%y;
    if (!z)
        return y;
    return z;
}
int rez(){
    int nr=0,L=0,aux;
    eliminare();
    if (i>=n)
       return 0;
    while (s[i] >= '0' && s[i] <= '9')
        nr=nr*10+(s[i]-'0'),i++;
    eliminare();
    while(s[i]=='('){
        i++;
        L=0;
        do{
            eliminare();
            L++;
            aux=l+1;
            v[++l]=rez();
            l=aux;
            eliminare();
            if(s[i]!=',')
                break;
            i++;
        }while(1);
        nr=v[l-L+procent(nr,L)];
        i++;
    }
    return nr;
}
int main(){
    fin.get(s,100005,'\n');
    n = strlen(s);
    fout<<rez();
    fin.close();
    fout.close();
    return 0;
}