zoukankan      html  css  js  c++  java
  • 一个翻牌算法

    自己对一个翻牌算法的实现:

    题目:拿出从A到10的10张扑克牌,背面朝上摞在一起。首先把最上面的一张挪到下面,掀开新出现的一张牌是A,取出,再挪一张牌到下面,翻一张是2,依次类推,可以有顺序地翻出A到10的牌来。请问这10张牌最初是怎么排列的?

     1 static void QueueImplement(int pokerCount = 10)
     2         {
     3             Queue primaryQueue = new Queue();
     4             Queue result = new Queue();
     5             for (int i = 1; i <= pokerCount; i++)
     6             {
     7                 primaryQueue.Enqueue(new PokerPosition() { orderInQueue = i, poker = new Poker() });
     8             }
     9 
    10             for (int order = 1; primaryQueue.Count > 0; order++)
    11             {
    12                 PokerPosition position = (PokerPosition)primaryQueue.Dequeue();
    13                 if (order % 2 == 0)
    14                 {
    15                     //取出
    16                     position.poker.num = result.Count + 1;
    17                     result.Enqueue(position);
    18                 }
    19                 else
    20                 {
    21                     primaryQueue.Enqueue(position);
    22                 }
    23             }
    24         }
     1 struct Poker
     2     {
     3         public int num;
     4         string type;
     5     }
     6 
     7     struct PokerPosition
     8     {
     9         public int orderInQueue;
    10         public Poker poker;
    11     }
  • 相关阅读:
    hangfire 本地可以正常打开hangfire页面,发布后报401
    core 引用webservice
    ABP自带原框架生成使用
    ABP框架问题排查记录
    转-image js binary
    贪心算法
    动态规划-练习
    分治算法-快速,归并
    ECMAScript5的新特性
    css-动画
  • 原文地址:https://www.cnblogs.com/anthonyBlog/p/2921273.html
Copyright © 2011-2022 走看看