Cod sursă (job #526758)

Utilizator avatar andrei_marciuc Marciuc Andrei andrei_marciuc IP ascuns
Problemă Bizar (clasele 9-10) Compilator cpp | 0,72 kb
Rundă Arhiva de probleme Status evaluat
Dată 11 feb. 2020 22:16:29 Scor 100
#include <fstream>
using namespace std;
int v[ 100001 ];
char x;

ifstream cin( "bizar.in" );
ofstream cout( "bizar.out" );

void p()
{
    cin.get( x );
    while( x == ' ' )
        cin.get( x );
}

int nr()
{
    int n = 0;
    while( isdigit( x ) ){
        n = n * 10 + x - '0';
        p();
    }
    return n;
}

int rec( int st )
{
    int n = nr(), cate = 0;
    while( x == '(' ){
        while( x != ')' ){
            p();
            v[ st + cate ] = rec( st + cate );
            ++cate;
            //p();
        }
        n = v[ st + ( n - 1 ) % cate ];
        cate = 0;
        p();
    }

    return n;
}

int main()
{
    p();
    cout << rec( 0 );
    return 0;
}