Pagini recente » Monitorul de evaluare | Statistici Florin Juravle (florindany68) | Istoria paginii utilizator/uknoit | Statistici Radu Radu (rhadookoo) | Cod sursa (job #1378412)
#include<iostream>
#include<fstream>
#include<cstring>
using namespace std;
int st[100005],n,top;
char s[100005];
void Citire()
{
ifstream fin("evaluare.in");
fin>>s;
n=strlen(s);
fin.close();
}
void Rezolvare()
{
int i,nr;
int semn,stiva;
top=-1;
i=0;
while(i<=n-1)
{
if(s[i]=='(')
{
st[++top]=1000000001;
i++;
}
if(s[i-1]=='(' && s[i]-'0'>=0 && s[i]-'0'<=9)
{
nr=0;
while(s[i]-'0'>=0 && s[i]-'0'<=9)
{
nr=nr*10+(s[i]-'0'); ///(1+1)*13+10/2
i++;
}
st[++top]=nr;
}
if(s[i]=='+')
{
nr=0; i++;
while(s[i]-'0'>=0 && s[i]-'0'<=9)
{
nr=nr*10+(s[i]-'0');
i++;
}
st[++top]=nr;
}
if(s[i]=='-')
{
nr=0; i++;
while(s[i]-'0'>=0 && s[i]-'0'<=9)
{
nr=nr*10+(s[i]-'0');
i++;
}
semn=-1;
st[++top]=nr*semn;
}
if(s[i]=='*')
{
nr=0; i++;
while(s[i]-'0'>=0 && s[i]-'0'<=9)
{
nr=nr*10+(s[i]-'0');
i++;
}
st[top]=st[top]*nr;
}
if(s[i]=='/')
{
nr=0; i++;
while(s[i]-'0'>=0 && s[i]-'0'<=9)
{
nr=nr*10+(s[i]-'0');
i++;
}
st[top]=st[top]/nr;
}
if (s[i]==')')
{
i++;
stiva=0;
while (st[top]!=1000000001)
{
stiva=stiva+st[top];
top--;
}
st[top]=stiva;
}
}
}
void Afisare()
{
int suma,i;
suma=0;
ofstream fout("evaluare.out");
for(i=0;i<=top;i++)
{
suma=suma+st[i];
}
fout<<suma<<"\n";
fout.close();
}
int main()
{
Citire();
Rezolvare();
Afisare();
return 0;
}