求助:死循环力【悲】
查看原帖
求助:死循环力【悲】
846034
Starkiller123楼主2023/7/14 17:40
#include<bits/stdc++.h>
using namespace std;
stack<int>m;
char ch[100];
int x,y;
int main()
{
	int i=1;
	while(ch[i]!='@')
	{
		cin>>ch[i];
		i++;
	}
	int a=0,b=0,c;
	i=1;int j;
	while(ch[i]!='@')
	{
		j=i;
		while(ch[j]!='.'&&ch[j]!='@')
		{
			if(ch[j]<='9'&&ch[j]>='0')
			{
				a=ch[j]-'0';
				c=b*10+a;
			}
			b=a;
			j++;
		}
		m.push(c);
		switch(ch[i])
		{
			case '+':x=m.top();m.pop();y=m.top();m.pop();m.push(x+y);break;
			case '-':x=m.top();m.pop();y=m.top();m.pop();m.push(y-x);break;
			case '*':x=m.top();m.pop();y=m.top();m.pop();m.push(x*y);break;
			case '/':x=m.top();m.pop();y=m.top();m.pop();m.push(y/x);break;
		}
		i=j+1;
	}
	cout<<m.top();
	return 0;
} 
2023/7/14 17:40
加载中...