Pagini recente » Cod sursa (job #670223) | Cod sursa (job #1059521) | Cod sursa (job #3189279) | Cod sursa (job #2482409) | Cod sursa (job #1814927)
#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 *= Chunk();
}
if (Storage[Level] == '/') {
Level++;
Prod /= Chunk();
}
}
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);
cin.getline(Storage,100000,'\n');
cout << Express();
}