题解 | 打牌

打牌

https://www.nowcoder.com/practice/d50d996e72dd4dedb3bbdf3809cff0d4


import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int total=scan.nextInt();
		while(total-->0) {
			int a=scan.nextInt();
			int b=scan.nextInt();
			Queue<Integer>a1=new LinkedList<>();
			Queue<Integer>b1=new LinkedList<>();
			for(int i=0;i<a;i++) {
				a1.offer(scan.nextInt());
			}
			for(int j=0;j<b;j++) {
				b1.offer(scan.nextInt());
			}
			int acount=0;
			int bcount=0;
			while(!a1.isEmpty()&&!b1.isEmpty()) {
				int a3=a1.poll();
				int b3=b1.poll();
				if(a3>b3) {
					acount++;
					a1.offer(a3);
				}else if(b3>a3) {
					bcount++;
					b1.offer(b3);
				}
			}
			if(acount>bcount) {
				System.out.println("alice");
			}else if(bcount>acount) {
				System.out.println("bob");
			}else {
				System.out.println("draw");
			}
			
		}
		scan.close();
	}
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务