Pagini recente » Cod sursa (job #606541) | Cod sursa (job #61119) | Cod sursa (job #1111539) | Cod sursa (job #2962793) | Cod sursa (job #1151380)
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <cstring>
using namespace std;
#define nmax 100005
ofstream out("evaluare.out");
char S[nmax], *p=S;
int termen();
int factor();
int eval(){
int r=termen();
if (*p=='+')
p++, r+=termen();
else if (*p=='-')
p++, r-=termen();
return r;
}
int termen(){
int r=factor();
if (*p=='*')
p++, r*=factor();
else if (*p=='/')
p++, r/=factor();
return r;
}
int factor(){
int r=0;
if (*p=='(')
p++, r=eval(), p++;
else {
while (*p>='0' && *p<='9'){
r=(r*10)+*p-'0';
p++;
}
}
return r;
}
int main(){
fgets(S, nmax, fopen("evaluare.in","r"));
out << eval();
return 0;
}