Pagini recente » Cod sursa (job #1742648) | Cod sursa (job #2004185) | Cod sursa (job #2774769) | Cod sursa (job #1258673) | Cod sursa (job #690540)
Cod sursa(job #690540)
# include <fstream>
# include <cstring>
# define dim 100005
using namespace std;
ifstream f("evaluare.in");
ofstream g("evaluare.out");
char a[ dim ];
int poz = 0;
inline int rezolva();
inline int valoare()
{
int val = 0;
while ( a[ poz ] <= '9' && a[ poz ] >= '0' )
{
val = val * 10 + ( a[ poz ] - '0' );
poz++;
}
// g << val << "\n";
return val;
}
inline int factor()
{
int val = 0;
if ( a[ poz ] == '(' )
{
poz++;
val = rezolva();
poz++;
}
else
val = valoare();
return val;
}
inline int termen()
{
int val = factor();
while ( a[ poz ] == '*' || a[ poz ] == '/' )
{
if ( a[ poz++ ] == '*' )
val = val * factor();
else
val = val / factor();
//poz++;
}
return val;
}
inline int rezolva()
{
int val = termen();
while ( a[ poz ] == '+' || a[ poz ] == '-' )
{
// g << val << "\n";
//poz ++;
if ( a[ poz++ ] == '+' )
val = val + termen();
else
val = val - termen();
//poz++;
}
return val;
}
inline void citire()
{
f.getline( a, dim );
}
int main()
{
citire();
g << rezolva();
return 0;
}