站外题求助(玄关)
  • 板块学术版
  • 楼主_TAT_
  • 当前回复3
  • 已保存回复3
  • 发布时间2024/4/15 19:57
  • 上次更新2024/4/15 21:35:01
查看原帖
站外题求助(玄关)
1073331
_TAT_楼主2024/4/15 19:57

题

我的做法是数组模拟栈,0分,求调试,不要代码谢谢 Thanks♪(・ω・)ノ

样例能过QWQ

#include<bits/stdc++.h>
using namespace std;
long long t[260];
string s;
long long TWT(string s)
{
    long long i=0,top=0,x=0;
    while(i<s.size()-1) 
    {
    	if(s[i]<='9'&&s[i]>='0') x=x*10+int(s[i]-'0');
    	else{
    		if(s[i]==' '&&s[i-1]>='0'&&s[i-1]<='9'){
                top++;
                t[top]=x;
                x=0;

            }
    		else{
                // cout<<t[top]<<endl;
                int n=t[top-1],m=t[top];
                top--;
    			if(s[i]=='+') t[top]=n+m;
    			else if(s[i]=='-') t[top]=n-m;
    			else if(s[i]=='*') t[top]=n*m;
    			else if(s[i]=='/') t[top]=n/m;
    			
			}
		}
		i++;
	}
	return t[top];
}
int main()
{            
	getline(cin,s);
	cout<<TWT(s);
	return 0;
}
2024/4/15 19:57
加载中...