#include <stdio.h>
#include <ctype.h>
FILE *fin, *fout;
// returneaza rezulatul calcului pana la un ')' sau pana la '\n'
int rezCalc() {
int ch = fgetc( fin ), sum = 1, rez = 0, p = 1, x, up = '*';
while ( ch != ')' && ch != '\n' ) {
if ( ch == '+' || ch == '-' )
p = ch == '+' ? 1 : -1;
if ( ch == '+' || ch == '-' || ch == '*' || ch == '/' ) {
up = ch == '/' ? '/' : '*';
ch = fgetc( fin );
}
if ( ch == '(' ) {
x = rezCalc();
sum = up == '*' ? sum * x : sum / x;
ch = fgetc( fin );
} else {
x = 0;
do
x = x * 10 + ch - '0';
while ( isdigit( ch = fgetc( fin ) ) );
sum = up == '*' ? sum * x : sum / x;
}
if ( ch != '*' && ch != '/' ) {
rez += sum * p;
sum = 1;
}
}
return rez;
}
int main() {
fin = fopen( "evaluare.in", "r" );
fout = fopen( "evaluare.out", "w" );
fprintf( fout, "%d\n", rezCalc() );
fclose( fin );
fclose( fout );
return 0;
}