难的是理解题目的意思啊,第二道题有简单的解法吗?没来得及,罗列情况弄好久,最后没时间
import java.util.LinkedList;
import java.util.Scanner;
public class 卡拉卡斯卡 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// while(sc.hasNext()){
int n = sc.nextInt();
int m = sc.nextInt();
int[] a = new int[m];
for(int i=0;i<m ;i++){
a[i] = sc.nextInt();
}
kolakoski(a,n);
// }
}
private static void kolakoski(int[] a, int n) {
LinkedList<Integer> res = new LinkedList<Integer>();
int i,j,temp,k;
for( i=0;i<a[0];i++){
res.add(a[0]);
}
j=1;
for(i=1;res.size()<n;i++){
if(i==res.size())
temp = a[j];
else
temp = res.get(i);
for(k=0;k<temp ;k++){
res.add(a[j]);
}
j++;
if(j%a.length ==0)
j=0;
}
for(i=0;i<n;i++)
System.out.println(res.get(i));
}
}