Cod sursă (job #285288)

Utilizator avatar Therevengerking Surani Adrian Therevengerking IP ascuns
Problemă Bizar (clasele 9-10) Compilator cpp | 0,75 kb
Rundă Arhiva de probleme Status evaluat
Dată 25 feb. 2017 15:15:22 Scor 100
#include <iostream>
#include <fstream>
#include <vector>
#include <cctype>
using namespace std;
ifstream fin("bizar.in");
ofstream fout("bizar.out");
string s,act;
int i=0;
int get_nr()
{
    int nr=0;
    while(isdigit(s[i]))
    {
        nr=nr*10+s[i]-'0';
        ++i;
    }
    return nr;
}
int eval()
{
    int poz;
    poz=get_nr();
    vector<int>v;
    while(s[i]=='(')
    {
        vector<int>v;
        while(s[i]!=')')
        {
            i++;
            v.push_back(eval());
        }
        ++i;
        poz=v[(poz+v.size()-1)%v.size()];
    }
    return poz;
}
int main()
{
    getline(fin,act);
    for(int i=0;i<act.size();++i)if(act[i]!=' ')s.push_back(act[i]);
    fout<<eval();
    return 0;
}