Cod sursa(job #2109938)
| Utilizator | Data | 20 ianuarie 2018 11:34:47 | |
|---|---|---|---|
| Problema | Evaluarea unei expresii | Scor | 60 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 1.31 kb |
#include <fstream>
#include <cstring>
using namespace std;
ifstream f("evaluare.in");
ofstream g("evaluare.out");
char s[100002];
int n, x;
int inmimp();
int paranteze();
int adunscad()
{
int y=inmimp();
while(s[x]=='+' || s[x]=='-')
{
switch(s[x])
{
case '+':
{
x++;
y+=inmimp();
break;
}
case '-':
{
x++;
y-=inmimp();
break;
}
}
}
return y;
}
int inmimp()
{
int y=paranteze();
while(s[x]=='*' || s[x]=='/')
{
switch(s[x])
{
case '*':
{
x++;
y*=inmimp();
break;
}
case '/':
{
x++;
y/=inmimp();
}
}
}
return y;
}
int paranteze()
{
int y=0;
if(s[x]=='(')
{
x++;
y=adunscad();
x++;
}
else
while(s[x]>='0' && s[x]<='9')
{
y=y*10+s[x]-48;
x++;
}
return y;
}
int main()
{
f.getline(s, 100002);
n=strlen(s);
g<<adunscad();
return 0;
}
