Pagini recente » Cod sursa (job #2377138) | Cod sursa (job #3211021) | Cod sursa (job #3265084) | Cod sursa (job #2050330) | Cod sursa (job #3263934)
#include <iostream>
using namespace std;
int p1(string &sir, int &poz);
int p2(string &sir, int &poz){
int total=p1(sir,poz);
while(sir[poz]=='*' || sir[poz]=='/'){
if(sir[poz]=='*'){
poz++;
total*=p1(sir,poz);
}
else{
poz++;
total/=p1(sir,poz);
}
}
return total;
}
int p3(string &sir, int &poz){
int total=p2(sir,poz);
while(sir[poz]=='+' || sir[poz]=='-'){
if(sir[poz]=='+'){
poz++;
total+=p2(sir,poz);
}
else{
poz++;
total-=p2(sir,poz);
}
}
return total;
}
int p1(string &sir, int &poz){
int total=0;
if(sir[poz]=='('){
poz++;
total+=p3(sir,poz);
poz++;
}
else{
while(sir[poz]>='0' && sir[poz]<='9'){
total*=10;
total+=sir[poz]-'0';
poz++;
}
}
return total;
}
int main()
{
string sir;
cin>>sir;
int poz=0;
cout<<p3(sir,poz);
return 0;
}