小猫钓鱼

#include
#include
#include
using namespace std;
int main()
{
queue a,b;
stack m;
int book[10]={0};
int n,y,t=0;
int sum=0;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>y;
a.push(y);
}
for(int i=0;i<n;i++)
{
cin>>y;
b.push(y);
}
while(!a.empty()&&!b.empty())
{
//a出牌
t=a.front();
a.pop();
if(book[t]==0)
{
m.push(t);
book[t]=1; //此处不删a.pop();
}
else
{
a.push(t);
while(m.top()!=t)
{
book[m.top()]=0; //m.top()是栈中间元素取出给队列a,不用t;
a.push(m.top());
m.pop();
}
}

	//b出牌 
	t=b.front();
	b.pop();
	if(book[t]==0)
	{
		m.push(t);
		book[t]=1;      //此处不删b.pop(); 
	} 
	else
	{
		b.push(t);
		while(m.top()!=t)
		{	
			book[m.top()]=0;    //m.top()是栈中间元素取出给队列b,不用t; 
			b.push(m.top());
			m.pop();
		}
	}
	sum+=2;         //判断出牌次数是否大于500
	if(sum>=1000)
	break; 
}
int suma=a.size();
int sumb=b.size();

//a 赢
if(suma>sumb)
{
	cout<<"A win!";
	if(suma==0)
	
		cout<<"A 赢的时候手里无牌"; 
	else
	{
		cout<<"A 赢时手里有:"; 
		while(!a.empty())
		{
			cout<<a.front()<<" ";
			a.pop(); 
		} 
	}
 } 
 else
{
	if(sumb==0)
		cout << "B赢的时候没有手牌 !\n";
	else
	{
		cout << "B赢的时候手牌有 : \n";
		while(!b.empty())
		{
			cout << b.front() << " ";
			b.pop();
		}
		cout << "\n";
	}
	cout << "A的手牌有 :\n";
	while(!a.empty())
	{
		cout << a.front() << " ";
		a.pop();
	}
}
cout << "牌堆里的牌有 : \n";
while(!m.empty())
{
	cout << m.top() << " ";
	m.pop();
}

return 0;

}

发布了22 篇原创文章 · 获赞 33 · 访问量 1090

猜你喜欢

转载自blog.csdn.net/qq_42577542/article/details/88959148