0pts求助
查看原帖
0pts求助
169594
Heart_Of_Iron_4楼主2022/10/1 13:28

评测记录:https://www.luogu.com.cn/record/88067282

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define gets(ttt) cin.getline(ttt,1145141919810)
char t1,ans[200],s[200],t3[200];
int top,len,t2,s1[200],top1,ansq,lent3;
int qz(char k)
{
	if(k=='^')return 3;
	if(k=='*'||k=='/')return 2;
	if(k=='+'||k=='-')return 1;
	if(k=='('||k==')')return 0;
	return -114514;
}
signed main()
{
	while(t1=getchar())
	{
		if(t1==10||t1==-1)break;
		if('0'<=t1&&t1<='9')
		{
			ans[++len]=t1;
		}
		else
		{
			if(t1=='(')s[++top]=t1;
			if(t1==')')
			{
				while(s[top]!='(')
				{
					ans[++len]=s[top];
					top--;
				}
				top--;
			}
			if(t1=='^')s[++top]=t1;
			if(t1=='+'||t1=='/'||t1=='-'||t1=='*')
			{
				while(qz(s[top])>=qz(t1))
				{
					ans[++len]=s[top];
					top--;
				}
				s[++top]=t1;
			}
		}
	}
	while(top)
	{
		ans[++len]=s[top];
		top--;
	}
	for(int i=1;i<=len;++i)
	{
		t3[++lent3]=ans[i];
		t3[++lent3]=' ';
	}
	lent3--;
	len=lent3;
	top1=0;
	for(int i=1;i<=len;++i)
	{
		ans[i]=t3[i];
	}
	for(int j=1;j<=len;++j)
		putchar(ans[j]);
	cerr<<endl;
	for(int i=1;i<=len;i+=2)
	{
		if(ans[i]<'0'||ans[i]>'9')
		{
			if(ans[i]=='+')
			{
				t2=s1[top1-1]+s1[top1];
				--top1;
				s1[top1]=t2;
			}
			else if(ans[i]=='-')
			{
				t2=s1[top1-1]-s1[top1];
				--top1;
				s1[top1]=t2;
			}
			else if(ans[i]=='*')
			{
				t2=s1[top1-1]*s1[top1];
				--top1;
				s1[top1]=t2;
			}
			else if(ans[i]=='/')
			{
				t2=s1[top1-1]/s1[top1];
				--top1;
				s1[top1]=t2;
			}
			else 
			{
				t2=pow(s1[top1-1],s1[top1]);
				--top1;
				s1[top1]=t2;
			}
			for(int j=1;j<=top1;++j)
			{
				printf("%lld ",s1[j]);
			}
			for(int j=i+2;j<=len;++j)
				putchar(ans[j]);
			puts("");
		}
		else
		{
			s1[++top1]=ans[i]-'0';
		}
	}
	return 0;
}
2022/10/1 13:28
加载中...