well,联合的标记问题。。。。怎么弄?
#include<iostream>
#include<stack>
using namespace std;
struct element
{
char op;
double nu;
};
int main()
{
stack<element> st;
char s[61];
gets(s);
double tmp;
for(int i=0;s[i]!='\0';++i)
{
if(s[i]==' ') continue;
else if(isdigit(s[i])||(s[i]=='-'&&isdigit(s[i+1])))
{
tmp=0;
bool flag=0;
if(s[i]=='-') {flag=1;++i;}
while(isdigit(s[i])) {tmp=tmp*10+s[i]-'0';++i;}
if(s[i]=='.')
{
if(s[i]=='.') ++i;
double t=0.1;
while(s[i]!=' ')
{
if(s[i]=='\0') break;
tmp+=(s[i]-'0')*t;
++i;
t/=10;
}
}
if(flag) tmp=-tmp;
while(!st.empty()&&st.top().op=='#')
{
double na=st.top().nu;
st.pop();
switch(st.top().op)
{
case'+':tmp=na+tmp;break;
case'-':tmp=na-tmp;break;
case'*':tmp=na*tmp;break;
case'/':if(tmp==0) {cout<<"ERROR";return 0;}tmp=na/tmp;break;
}
st.pop();
}
element ele;
ele.op='#';
ele.nu=tmp;
st.push(ele);
}
else
{
element ele;
ele.op=s[i];
ele.nu=0;
st.push(ele);
}
}
printf("%.1lf",tmp);
}