1 条题解
-
0
C :
#include <stdio.h> main(){ int n,t=-1,i=0,a[255];char s[255]; gets(s); while(s[i]!='@'){n=0; while(s[i]>='0'&&s[i]<='9'){ n=n*10+s[i]-'0';i++; } if(n!=0){++t;a[t]=n;} if(s[i]=='+'){a[t-1]=a[t-1]+a[t];t--;} if(s[i]=='-'){a[t-1]=a[t-1]-a[t];t--;} if(s[i]=='*'){a[t-1]=a[t-1]*a[t];t--;} if(s[i]=='/'){a[t-1]=a[t-1]/a[t];t--;} i++; } printf("%d ",a[0]); }
C++ :
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cstdlib> #include<cctype> #include<stack> #define num x using namespace std; stack<int>num,sym; int a[255]; char s[300]; int main(){ /*freopen("strs.in","r",stdin); freopen("strs.out","w",stdout);//*/ char ch; ch=getchar(); while(ch!='@'){ int k=0; while(isalnum(ch)){ k=k*10+ch-48; ch=getchar(); } //cout<<k<<' '; if(!(ch!='0'&&k==0))num.push(k); while(ch==' ')ch=getchar(); //cout<<ch; if(!isalnum(ch)){ if(ch=='+'){ int k1=x.top(); x.pop(); int k2=x.top(); x.pop(); x.push(k1+k2); } else if(ch=='-'){ int k1=x.top(); x.pop(); int k2=x.top(); x.pop(); //cout<<k1<<' '<<k2; x.push(k2-k1); } else if(ch=='*'){ int k1=x.top(); x.pop(); int k2=x.top(); x.pop(); x.push(k2*k1); } else if(ch=='/'){ int k1=x.top(); x.pop(); int k2=x.top(); x.pop(); x.push(k2/k1); } ch=getchar(); while(ch==' ')ch=getchar(); } } int k=x.top(); cout<<k; //while(1); return 0; }
- 1
信息
- ID
- 402
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者