搜狐笔试第一题精简版,ac
输入不写了,主要看代码逻辑
public class Main { public static void main(String[] args) { int n = 30; int m = 4; int[] v = new int[]{2,1,3,1}; int i = 0; int j = 0; int k = 1; int q = 0; int[] res = new int[200]; res[0] = v[0]; while(i<n){ if(k<res[i]){ res[q+1] = res[q]; k++; q++; }else{ k = 1; j++; i++; j%=m; res[q+1]=v[j]; q++; } } for(int p = 0;p<n;p++){ System.out.println(res[p]); } } }