下面展示一些 内联代码片
。
// A code block
var foo = 'bar';
// An highlighted block
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<cstdlib>
#include<algorithm>
using namespace std;
const int maxn=50;
string c[maxn];
int cnt; stack<double>st;
int main(){
while(cin>>c[cnt])
{
cnt++;
}
for(int i=cnt-1;i>=0;i--){
if(c[i]=="+"||c[i]=="-"||c[i]=="*"||c[i]=="/")
{
if(st.empty())
{
cout<<"ERROR"<<endl;
return 0;
}
double x=st.top();
st.pop();
if(st.empty()){
cout<<"ERROR"<<endl;
return 0;
}
double y=st.top();
st.pop();
if(c[i]=="+")
st.push(x+y);
if(c[i]=="-")
st.push(x-y);
if(c[i]=="/"){
if(y==0)
{
cout<<"ERROR"<<endl;
return 0;
}
st.push(x/y);
}
if(c[i]=="*")
st.push(x*y);
}
else
{
double x=atof(c[i].c_str());
st.push(x);
}
}
printf("%.1f\n",st.top());
return 0;
}