Cod sursa(job #2655137)

Utilizator mitocaru_marioMitocaru Mario-Alexandru mitocaru_mario Data 3 octombrie 2020 13:18:19
Problema Evaluarea unei expresii Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.86 kb
#include <bits/stdc++.h>
using namespace std;
ifstream f("evaluare.in");
ofstream g("evaluare.out");

int E(),T(),F(),N();char c;
int main()
{
    g<<E();
    return 0;
}
int E()
{
    f>>c;
    int R=T();
    while(c=='+'||c=='-')
        if(c=='+')
        {
            f>>c;
            R+=T();
        }
        else
        {
            f>>c;
            R-=T();
        }
    return R;
}
int T()
{
    int R=F();
    while(c=='*'||c=='/')
        if(c=='*')
        {
            f>>c;
            R*=F();
        }
        else
        {
            f>>c;
            R/=F();
        }
    return R;
}
int F()
{
    if(isdigit(c))
    return N();
    int R=E();
    f>>c;
    return R;
}
int N()
{
    int R=0;
    while(isdigit(c))
    {
        R=10*R+c-'0';
        if(!(f>>c))c=0;;
    }
    return R;
}