#include<stdio.h> //猴子選大王吧 //直接模擬,循環一圈後會亂?把未選出的數字放到覆蓋到原來的數組上 //設置K來確定不亂 void fun(int *A,int *B,int temp,int n) { int i,j,k,ib,stop; k=temp; stop=n; i=stop+1; j=stop; ib=0; while(ib<n) { if(i>=stop) { stop=j; i=j=0; } if(--k!=0)//k的作用確保開始後的順序不會亂 { A[j++]=A[i++]; } else { B[ib++]=A[i++]; k=temp; } } } int main() { int num[10]={1,2,3,4,5,6,7,8,9,10};//測試數據 int here[10]; fun(num,here,2,10); for(int i=0;i<10;i++) printf("%d ",here[i]); }