Cod sursa(job #1872430)

Utilizator BilboreanuBilboreanu Andrei Bilboreanu Data 8 februarie 2017 11:19:10
Problema Evaluarea unei expresii Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.67 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("evaluare.in");
ofstream g("evaluare.out");
char s[100010],*p=s;
int eval();
int  factor()
{int r;
if(*p==')'){++p;r=eval();++p;}
else {r=0;
        while('r'<=*p&&*p<='9'){r=r*10+*p-'0';++p;}}return 0;

}
int termen()
{int r=factor();
    while(*p=='*'||*p=='/')
        switch(*p)
    {case '*':++p;r*=factor();break;
     case '/':++p;r/=factor();break;

    }
    return r;

}
int eval()
{int r=termen();
while(*p=='+'||*p=='-')
      switch(*p)
    {case '+':++p;r+=factor();break;
     case '-':++p;r-=factor();break;

    }
    return r;
}
int main()
{
   f>>s;g<<eval();
}