#include <cstdlib>
#include <cstdio>
#include <iostream>
void evalPf(char*);
double cal(double, char, double);
using namespace std;
int main(int argc, char *argv[])
{
char input[50];
cin.unsetf(ios::skipws);
cin>>input;
evalPf(input);
system("PAUSE");
return EXIT_SUCCESS;
}
void evalPf(char* postfix) {
double stack[80];
char temp[2];
char token;
int top = 0, i = 0;
temp[1] = '\0';
while(1) {
token = postfix[i];
switch(token) {
case '\0':
printf("ans = %f\n", stack[top]);
return;
case '+': case '-': case '*': case '/':
stack[top-1] =
cal(stack[top-1], token, stack[top]);
top--;
break;
default:
if(top < sizeof(stack) / sizeof(float)) {
temp[0] = postfix[i];
top++;
stack[top] = atof(temp);
}
break;
}
i++;
}
}
double cal(double p1, char op, double p2) {
switch(op) {
case '+':
return p1 + p2;
case '-':
return p1 - p2;
case '*':
return p1 * p2;
case '/':
return p1 / p2;
}
}
I2luY2x1ZGUgPGNzdGRsaWI+CiNpbmNsdWRlIDxjc3RkaW8+IAojaW5jbHVkZSA8aW9zdHJlYW0+CnZvaWQgZXZhbFBmKGNoYXIqKTsgCmRvdWJsZSBjYWwoZG91YmxlLCBjaGFyLCBkb3VibGUpOyAKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKGludCBhcmdjLCBjaGFyICphcmd2W10pCnsKICAgIGNoYXIgaW5wdXRbNTBdOwogICAgY2luLnVuc2V0Zihpb3M6OnNraXB3cyk7IAoJY2luPj5pbnB1dDsgICAgICAKICAgIGV2YWxQZihpbnB1dCk7ICAKICAgIHN5c3RlbSgiUEFVU0UiKTsKICAgIHJldHVybiBFWElUX1NVQ0NFU1M7Cn0Kdm9pZCBldmFsUGYoY2hhciogcG9zdGZpeCkgeyAKICAgIGRvdWJsZSBzdGFja1s4MF07IAogICAgY2hhciB0ZW1wWzJdOyAKICAgIGNoYXIgdG9rZW47IAogICAgaW50IHRvcCA9IDAsIGkgPSAwOyAgCiAgICB0ZW1wWzFdID0gJ1wwJzsgIAogICAgd2hpbGUoMSkgeyAKICAgICAgICB0b2tlbiA9IHBvc3RmaXhbaV07IAogICAgICAgIHN3aXRjaCh0b2tlbikgeyAKICAgICAgICAgICAgY2FzZSAnXDAnOiAKICAgICAgICAgICAgICAgIHByaW50ZigiYW5zID0gJWZcbiIsIHN0YWNrW3RvcF0pOyAKICAgICAgICAgICAgICAgIHJldHVybjsgCiAgICAgICAgICAgIGNhc2UgJysnOiBjYXNlICctJzogY2FzZSAnKic6IGNhc2UgJy8nOiAKICAgICAgICAgICAgICAgIHN0YWNrW3RvcC0xXSA9IAogICAgICAgICAgICAgICAgICAgICAgIGNhbChzdGFja1t0b3AtMV0sIHRva2VuLCBzdGFja1t0b3BdKTsgCiAgICAgICAgICAgICAgICB0b3AtLTsgCiAgICAgICAgICAgICAgICBicmVhazsgCiAgICAgICAgICAgIGRlZmF1bHQ6IAogICAgICAgICAgICAgICAgaWYodG9wIDwgc2l6ZW9mKHN0YWNrKSAvIHNpemVvZihmbG9hdCkpIHsgCiAgICAgICAgICAgICAgICAgICAgdGVtcFswXSA9IHBvc3RmaXhbaV07IAogICAgICAgICAgICAgICAgICAgIHRvcCsrOyAKICAgICAgICAgICAgICAgICAgICBzdGFja1t0b3BdID0gYXRvZih0ZW1wKTsgCiAgICAgICAgICAgICAgICB9IAogICAgICAgICAgICAgICAgYnJlYWs7IAogICAgICAgIH0gCiAgICAgICAgaSsrOyAKICAgIH0gCn0KZG91YmxlIGNhbChkb3VibGUgcDEsIGNoYXIgb3AsIGRvdWJsZSBwMikgeyAKICAgIHN3aXRjaChvcCkgeyAKICAgICAgICBjYXNlICcrJzogCiAgICAgICAgICAgIHJldHVybiBwMSArIHAyOyAKICAgICAgICBjYXNlICctJzogCiAgICAgICAgICAgIHJldHVybiBwMSAtIHAyOyAKICAgICAgICBjYXNlICcqJzogCiAgICAgICAgICAgIHJldHVybiBwMSAqIHAyOyAKICAgICAgICBjYXNlICcvJzogCiAgICAgICAgICAgIHJldHVybiBwMSAvIHAyOyAKICAgIH0gCn0=