S1417830194 @ 2024-03-11 21:50:31
#include <iostream>
#include <stack>
using namespace std;
stack<long long> number;
int main()
{
long long temp=0;char ch;
bool flag=false;
while( ( ch=getchar() )!='\n')
{
if(flag && ch>='0' && ch<='9' )
{
temp*=10;temp+=ch-'0';continue;
}
if(ch=='.')
{
number.push(temp);flag=false;temp=0;
continue;
}
else if(ch>='0' && ch<='9')
{
temp=ch-'0';flag=true;
continue;
}
else if(ch=='@')
cout<<number.top();
else
{
int A=number.top(); number.pop();//删去该pop语句和下面的pop语句会出现五个TLE
int B=number.top(); number.pop();
switch(ch)
{
case '*':
number.push(A*B);break;
case '/':
number.push(B/A);break;
case '+':
number.push(A+B);break;
case '-':
number.push(B-A);break;
}
}
}
return 0;
}
by __lihaoyu68__ @ 2024-03-28 18:16:57
#include<bits/stdc++.h>
using namespace std;
long long stk[1000];
int main(){
long long i=0,now=0;
char op;
while((op=getchar())!='@'){
if(op>='0'&&op<='9') now*=10,now+=op-'0';
else if(op=='.'){
stk[++i]=now;
now=0;
}
else if(op=='+'){
stk[i-1]=stk[i-1]+stk[i];
stk[i]=0;
i--;
}
else if(op=='-'){
stk[i-1]=stk[i-1]-stk[i];
stk[i]=0;
i--;
}
else if(op=='*'){
stk[i-1]=stk[i-1]*stk[i];
stk[i]=0;
i--;
}
else if(op=='/'){
stk[i-1]=stk[i-1]/stk[i];
stk[i]=0;
i--;
}
}
cout<<stk[1];
return 0;
}