基础题,由于数据量很小,所以直接依次查找直到最后一张牌即可。
#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;
}
继续加油。