求助
查看原帖
求助
746267
Glooda楼主2023/4/20 21:09

为啥没法输出啊,而且时间复杂度高的快要炸了

代码是参考洛谷的深入浅出上15-5内容上的算法写的

声明:没有照搬书上的代码,是借鉴后参考着自己手写的代码,算法是参照书上的,但代码绝对自己写的
#include<bits/stdc++.h>
using namespace std;
int main(){
	int s,a,b;
	stack<int> n;//
	char text;
	do{
		text=getchar();//每次只读入一个 
		if(text>='0'||text<='9'){
			s=s*10+text-'0';
		}
		else
		if(text='.'){
			n.push(s);
			s=0;
		}
		else if(text!='@'){
			a=n.top();
			n.pop();
			b=n.top();//此时栈中前两个元素待运算
			if(text=='+'){
				n.push(a+b);//压入 
			}
			else
			if(text=='-'){
				n.push(b-a);
			}
			else
			if(text=='*'){
				n.push(a*b);
			}
			else
			if(text=='/'){
				n.push(a/b); 
			}
		}
		}while(text!='@');
	printf("%d/n",n.top());
	return 0;
}

希望dalao能解答疑问,初次接触数据结构

2023/4/20 21:09
加载中...