玄关
  • 板块灌水区
  • 楼主wtqlw
  • 当前回复20
  • 已保存回复20
  • 发布时间2024/10/12 19:04
  • 上次更新2024/10/12 21:02:41
查看原帖
玄关
1059868
wtqlw楼主2024/10/12 19:04
#include<bits/stdc++.h>
using namespace std;
string s;
bool isdigit(char a)
{
	if(a>='0' && a<='9')
	{
		return true;
	}
	return false;
}
char st[100];
int hh=-1;
int main()
{
	cin>>s;
	int n=s.length();
	map <char,int> mp={{'+',1},{'-',1},{'/',2},{'*',2}};
	for(int i=0;i<n;i++)
	{
		if(isdigit(s[i]))
		{
			int res=0;
			int j=i;
			while(j<n && isdigit(s[j]))
			{
				res=res*10+(s[j]-'0');
				j++;
			}
			i=j-1;
			cout<<res<<" ";
		}
		else if(s[i]==')')
		{
			while(hh!=-1)
			{
				if(st[hh]=='(')
				{
					hh--;
					break;
				}
				cout<<st[hh--]<<" ";
			}
		}
		else if(s[i]=='(')
		{
			st[++hh]='(';
		}
		else
		{
			while(hh!=-1 && st[hh]!='(' && mp[st[hh]]>=mp[s[i]])
			{
				cout<<st[hh--]<<" ";
			}
			st[++hh]=s[i];
		}
	}
	while(hh!=-1)
	{
		cout<<st[hh--]<<" ";
	}
}

哪编译错误了

2024/10/12 19:04
加载中...