搜狐笔试编程第一题(还差5分钟没提交上= =)

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	private static Scanner sc;
	public static void main(String[] args) {
		int print_count = 0;
		int arr_len = 0;
		int count = 0;
		int tmp_count = 1;
		sc = new Scanner(System.in);
		print_count = sc.nextInt();
		arr_len = sc.nextInt(); 
		int[] arr = new int[arr_len];
		for(int i = 0;i<arr_len;i++) {
			arr[i] = sc.nextInt();
		}
		Queue<Integer> queue = new LinkedList<Integer>();
		for(int j = 0;j<arr[0];j++) {
			queue.offer(arr[0]);
		}
		if(arr_len == 1) {
			System.out.println(queue.poll());
			return;
		}else {
			System.out.println(queue.poll());
		}
		while(count<print_count-2) {
			if(queue.isEmpty()) {
				for(int t = 0;t<arr[tmp_count%arr_len];t++) {
					queue.offer(arr[tmp_count%arr_len]);
				}
				System.out.println(queue.poll());
				tmp_count++;
			}
			int tmp_print = queue.poll();
			for(int k = 0;k<tmp_print;k++) {
				queue.offer(arr[tmp_count%arr_len]);
			}
			tmp_count++;
			System.out.println(tmp_print);
			count++;
		}
		sc.close();
	}
}

#搜狐#
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务