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; }
Pascal :
program track;var t1:array[1..10000] of longint; top,n,i:integer; rd:char; f:boolean;begin rd:=' '; top:=0; f:=false; while rd<>'@' do begin read(rd); n:=0; while (rd in ['0'..'9']) do begin f:=true; n:=n*10+ord(rd)-ord('0'); read(rd); end; if f then begin inc(top); t1[top]:=n; f:=false;end; if rd in ['+','-','*','/'] then begin case rd of '+':t1[top-1]:=t1[top-1]+t1[top]; '-':t1[top-1]:=t1[top-1]-t1[top]; '*':t1[top-1]:=t1[top-1]*t1[top]; '/':t1[top-1]:=t1[top-1] div t1[top]; end; dec(top); end; end; write(t1[1]);end.
- 1
信息
- ID
- 880
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者