栈 普及-:P1449 后缀表达式 洛谷

栈 普及-:P1449 后缀表达式 洛谷_第1张图片

 

#include 
using namespace std;
stack sta;
//vetor sta;
int topAndPop(){
	int a = sta.top();
//	cout<<"a:"<>str; 
	int i;
		long long int n = 0;
	for( i=0;i='0'&&str[i]<='9'){
			n *= 10;  
			n += str[i] - '0';	
		}
		if(str[i]=='.'){
			sta.push(n);
			n=0;
		}
		if(str[i]=='+'){
			c = topAndPop();
			d = topAndPop();
			sta.push(c+d);
		}
		if(str[i]=='-'){
			c = topAndPop();
			d = topAndPop();
			sta.push(d-c);
		}
		if(str[i]=='*'){
			c = topAndPop();
			d = topAndPop();
			sta.push(c*d);
		}
		if(str[i]=='/'){
			c = topAndPop();
			d = topAndPop();
			sta.push(d/c);
		}
		if(str[i]=='@'){
			break;
		}
	}
	cout<

总结不要老看别人的题解,然后自己debug不了的,就打印问题一下就出来了。

你可能感兴趣的:(c++,栈)