Pagini recente » Cod sursa (job #1295094) | Cod sursa (job #2057944) | Cod sursa (job #961806) | Cod sursa (job #1821938) | Cod sursa (job #1814943)
#include <iostream>
#include <stdio.h>
using namespace std;
//GLOBALS DIVISION//
char Storage[100001];
int Level;
//PROTOTYPE DIVISION//
int Express();
int Chunk();
int Particle();
//PROCEDURES DIVISION//
int Express() {
int Sum = Chunk();
while (Storage[Level] == '+' || Storage[Level] == '-') {
if (Storage[Level] == '+') {
Level++;
Sum += Chunk();
}
if (Storage[Level] == '-') {
Level++;
Sum -= Chunk();
}
}
return Sum;
}
int Chunk() {
int Prod = Particle();
while (Storage[Level] == '*' || Storage[Level] == '/') {
if (Storage[Level] == '*') {
Level++;
Prod *= Particle();
}
if (Storage[Level] == '/') {
Level++;
Prod /= Particle();
}
}
return Prod;
}
int Particle() {
int Number = 0, Sign = 1;
while (Storage[Level] == '-') {
Level++;
Sign = -Sign;
}
if (Storage[Level] == '(') {
Level++;
Number = Express();
Level++;
return Sign * Number;
}
while (Storage[Level] >= '0' && Storage[Level] <= '9') {
Number = Number * 10 + Storage[Level] - '0';
Level++;
}
return Sign * Number;
}
int main() {
freopen("evaluare.in", "r", stdin);
freopen("evaluare.out", "w", stdout);
fgets(Storage,100000,stdin);
printf("%d",Express());
}