各位大佬请问是哪里写错了(玄关)
查看原帖
各位大佬请问是哪里写错了(玄关)
1199534
ycy1124楼主2024/3/30 12:22
#include<bits/stdc++.h>
using namespace std;
stack <long long int> a;
void read(long long int &b)
{
	int f=1;
	char ch=getchar();
	if(ch<'0'||ch>'9')
	{
		f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		b*=10;
		b+=ch-'0';
		ch=getchar();
	}
	b*=f;
}
void write(int b)
{
	char ch;
	if(b<0)
	{
		b=abs(b);
		putchar('-');
	}
	if(b==0)
	{
		putchar('0');
	}
	ch=char(b%10+'0');
	while(b)
	{
		putchar(ch);
		b/=10;
		ch=char(b%10+'0');
	}
	putchar('\n');
}
int main()
{
	string s;
	long long int x,n;
	long long int T;
	read(T);
	for(int i=1;i<=T;i++)
	{
		read(n);
		while(!a.empty())
		{
			a.pop();
		}
		for(int j=1;j<=n;j++)
		{
			cin>>s;
			if(s=="push")
			{
				read(x);
				a.push(x);
			}
			else if(s=="pop")
			{
				if(a.empty())
				{
					printf("Empty\n");
				}
				else
				{
					a.pop();
				}
			}
			else if(s=="query")
			{
				if(a.empty())
				{
					printf("Anguei!\n");
				}
				else
				{
					write(a.top());
				}
			}
			else
			{
				write(a.size());
			}
		}
	}
	return 0;
}
2024/3/30 12:22
加载中...