望大神告诉扑克牌问题的思路

lgp142788 2016-10-23 09:25:43
有1——n号卡片放成一叠,背面朝上 
1)将最上面的一张放到最下面 
2)打开目前的最上面的一张卡片,并将此卡片放在边上的一叠的最上面 
3)重复1)2)直到所有的卡片均打开为止 
4)新的这叠卡片的编号依次为1、2、……、n 
求这叠卡片原来的顺序。 
请用循环队列解决此问题。
...全文
306 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ooolinux 2016-10-23
  • 打赏
  • 举报
回复
小时候玩过这个,倒背如流。
lgp142788 2016-10-23
  • 打赏
  • 举报
回复
已采纳,谢谢啦
ooolinux 2016-10-23
  • 打赏
  • 举报
回复
完整的版本在这里,可以输入N的大小,用C的动态分配数组: http://blog.163.com/tab_98/blog/static/11924097201692314754324/
ooolinux 2016-10-23
  • 打赏
  • 举报
回复
引用 1 楼 u010165006 的回复:
小时候玩过这个,倒背如流。
不过忘了是13张还是52张。
// Poker.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
using namespace std;

struct Node
{
	int no;
	int value;
	bool hasValue;
};

int _tmain(int argc, _TCHAR* argv[])
{
	Node poker[53];

	for(int i=1;i<=52;i++)
	{
		poker[i].no=i;
		poker[i].hasValue=false;
	}

	for(int i=0,value=1,count=0;count<52;)
	{
		for(int j=0;j<2;j++)
		{
			do
			{
				i++;  
				if(i>52)
					i=1;
			}while(poker[i].hasValue);
		}
		poker[i].value=value++;
		poker[i].hasValue=true;
		count++;
	}

	for(int i=1;i<=52;i++)
		cout<<poker[i].value<<"  ";
	cout<<endl;

	return 0;
}

运行结果: 46 1 27 2 40 3 28 4 51 5 29 6 41 7 30 8 47 9 31 10 42 11 32 12 50 13 33 14 43 15 34 16 48 17 35 18 44 19 36 20 52 21 37 22 45 23 38 24 49 25 39 26

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧