8_2.cpp
资源名称:c.rar [点击查看]
上传用户:puke2000
上传日期:2022-07-25
资源大小:912k
文件大小:1k
源码类别:

C#编程

开发平台:

Visual C++

  1. //8_2
  2. #include <iostream.h>
  3. bool assign();
  4. int num,interval;
  5. void main()
  6. {
  7.   if(!assign())
  8.     return;
  9.   int* a=new int[num];
  10.   for(int i=0; i<num; i++)
  11.     cout <<(a[i]=i+1) <<",";
  12.   cout <<endl;
  13.   int i=(interval-1)%num;
  14.   for(int k=1; k<num; k++){
  15.     cout <<a[i] <<",";
  16.     a[i]=0;
  17.     for(int j=1; !(a[i]&&(j++==interval)); i=(i+1)%num);  //数数
  18.   }
  19.   cout <<"nNo." <<a[i] <<" boy has won.n";    //输出胜利者
  20.   delete[]a;
  21. }
  22. bool assign()
  23. {
  24.   while(1){
  25.     cout <<"please input the number of boys,the interval:n";
  26.     cin >>num >>interval;
  27.     if(num>1&&interval>1&&interval<num)
  28.       return true;
  29.     bool sign=true;
  30.     while(sign){
  31.       cout <<"error on your input data.n";
  32.       cout <<"please select following operation:n";
  33.       cout <<"ttstop at once!  ----- 1n";
  34.       cout <<"ttinput again. ------- 2n";
  35.       cout <<"ttas default values -- 3nn";
  36.       int sele=0;
  37.       cin >>sele;
  38.       switch(sele){
  39.         case 1: return false;
  40.         case 2: sign=false; break;
  41.         case 3: num=10; interval=3; return true;
  42.       }  //end of switch
  43.     }  //end of inner while
  44.   }  //end of out while
  45. }