#include #include #include #include // #include // #include // #include #define oo 1000000000 #define PI 3.14159265389793 #define EPS 1e-9 #define DBG(x) #define PRINT(x) cout << (#x) << " = " << x << endl #define MAX(a,b) ((a)>(b)?(a):(b)) #define MIN(a,b) ((a)<(b)?(a):(b)) int polynom[1000]; int constloop[1000]; char keyword[1000]; int ebene; int cebene; ifstream in("complex.in"); void test(char *a, char *b) { if( strcmp(a,b) != 0) cerr << "ERROR in TEST" << a << " b " << b << endl; } int eq(char *a, char *b) { return (strcmp(a,b) == 0); } int op() { int number; in >> number; //polynom[ebene]+=number; in >> keyword; DBG( cout << "OP" << number << endl ); return number; } int statementlist(); // forward for loop int loopstatement () { char c; int mal=1; int ret=0; in >> c; if( c == 'n' ) { ebene++; cebene++; in >> keyword; for(int i=0; i> number; in >> keyword; DBG( cout << "Constloop before : " << constloop[ebene] << endl); constloop[cebene]*=number; DBG( cout << "Setting constloop " << constloop[cebene] << " ebene " << ebene << " number " << number << endl); // for(int i=0; i> keyword; DBG( cout << "Loop "<> keyword; DBG( test(keyword, "BEGIN") ); in >> keyword; ret = statementlist(); DBG( test(keyword, "END") ); in >> keyword; // DBG( cout<< "Read keyword after end: " << keyword << endl ); return ret; } void output() { bool didSth=false; cout << "Runtime = "; for(int i=999; i>=0; i--) { if( polynom[i] > 0) { if( didSth ) cout << "+"; didSth=true; if( polynom[i] != 1 || (i==0) ) { cout << polynom[i]; } if( polynom[i] != 1 && i>=1) cout << "*"; if( i>1 ) cout << "n^" << i; else if(i==1) cout << "n"; } } if( !didSth ) cout << "0"; cout << "\n\n"; } int main(){ int numberOfProblems; in >> numberOfProblems; in >> keyword; for(int i=0; i