HDU 1457(Counting Out)

基础题,由于数据量很小,所以直接依次查找直到最后一张牌即可。

#include <iostream>
#include <string>
using namespace std;

struct card //扑克牌
{
	string s; //字符串
	bool vis; //是否已使用
}c[55];

int main()
{
	int k;
	while (cin >> k)
	{
		if (k == 0)
			break;

		for (int i = 51; i >= 0; i--) //输入所有牌
		{
			cin >> c[i].s;
			c[i].vis = false;
		}

		int count, index = 0; //计数,索引
		for (int i = 0; i < 51; i++) //按要求抽出51张牌
		{
			count = 0;
			while (count != k + 1)
			{
				if (c[index].vis == false)
					++count;	
				if (count < k + 1)
					++index;
				if (index == 52)
					index = 0;
			}
			c[index].vis = true;
		}
		for (int i = 0; i < 52; i++) //剩余最后一张牌
		{
			if (c[i].vis == false)
				cout << c[i].s << endl;
		}
	}
	return 0;
}

继续加油。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值