卡片游戏

来源:互联网 发布:淘宝卡索卫浴靠谱吗 编辑:程序博客网 时间:2024/04/27 20:14


/*卡片游戏*/
#include<math.h>
#include<iostream>
#include<stdio.h>
#include<string>
using namespace std;
#define max 100
int a[max];

int main()
{
 int i;
 int n;
 while (cin >> n)
 {
  int found = 0;//找最后一个数要用到
  for (i = 0; i <= n - 1; i++)
  {
   a[i] = i + 1;
  }//按下标赋值
  int j = 1;
  int number = n ;
  int count = 0;//计算除去的个数
  for (i = 0;; i++)
  {
   if (count == n - 1)
   {
    break;
   }

   if (a[i]==0) continue;
   cout << a[i] << "  ";//输出
   //cout << "count=" << count;
   a[i] = 0;//后排除
   if (a[i + 2] != 0)
   {
    a[number] = a[i + 1];//将下一项移到最后
    a[i + 1] = 0;//令下一项不存在
    
   }
   count++;
   number++;
  }
  for (i = 0; found != 1; i++)

  {
   if (a[i] != 0)
   {
    found = 1;
    cout << a[i] << endl;
   }
  }
 }
  system("pause");
  return 0;

}

0 0
原创粉丝点击