# 寒冬作业 洗牌2

public class 荷官洗牌 {

public static void main(String[] args) {
int[] card = new int[52];
int[] ans = new int[52];
int n=card.length;
for(int i=0;i<n;i++)
card[i]=i+1;
int mid = (int)(Math.random()*52);
int i=0,j=mid,p=0;//3个指针

while(i<mid && j<n)//当2堆牌都不为空时，循环继续
{
ans[p++]=card[i++];
ans[p++]=card[j++];
}
while(i<mid)//把左部分剩余没发完的发下去
ans[p++]=card[i++];
while(j<n)//把右部分剩余没发完的发下去
ans[p++]=card[j++];
//测试
System.out.println("mid:"+mid);
for(int x:ans)
System.out.print(x+" ");
}

}


/**
*
* @author 叶叶
*
*/
public class 普通人洗牌 {

public static void main(String[] args) {
int[] card = new int[52];
int[] ans = new int[52];
int n=card.length;
for(int i=0;i<n;i++)
card[i]=i+1;
int mid = (int)(Math.random()*52);
int i=0,j=mid,p=0;//3个指针
while (i < mid && j < n) {
int x = 1 + (int) (Math.random() * 3);
int y = 1 + (int) (Math.random() * 3);
for (int k = 0; k < x && i<mid; k++)//随机的k小于发牌数，同时下标也要小于mid
ans[p++] = card[i++];
for (int k = 0; k < y && j<n; k++)//随机的k小于发牌数，同时下标也要小于n
ans[p++] = card[j++];
}
while(i<mid)
ans[p++]=card[i++];
while(j<n)
ans[p++]=card[j++];
//测试
System.out.println("mid:"+mid);
for(int x:ans)
System.out.print(x+" ");
}

}