Cod sursă (job #159191)

Utilizator avatar cips Stanciu Gabriel-Ciprian cips IP ascuns
Problemă Bizar (clasele 9-10) Compilator cpp | 0,61 kb
Rundă Arhiva de probleme Status evaluat
Dată 11 oct. 2015 13:26:07 Scor 100
#include <fstream>
using namespace std;

ifstream fin ("bizar.in");

int V[100000];
char e;

void nxtC(){
	e=fin.get();
	while (e==' ')
		e=fin.get();
}

int nxtNum(){
	int num=0;
	while (e>='0' && e<='9'){
		num=num*10+(e-'0');
		nxtC();
	}
	return num;
}

int EvalExpr(int shft){
	int num=nxtNum(), nr=0;
	while (e=='('){
		while (e!=')'){
			nxtC();
			V[shft+nr]=EvalExpr(shft+nr);
			nr++;
		}
		num=V[shft+(num-1)%nr];
		nr=0;
		nxtC();
	}
	return num;
}

int main(){
	nxtC();
	ofstream fout ("bizar.out");
	fout << EvalExpr(0);
	fin.close(); fout.close();
	return 0;
}