题解 | 纸牌游戏

纸牌游戏

https://www.nowcoder.com/practice/74f915e366094b19b94334de8b68e733



import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scanner=new Scanner(System.in);
		int a[]=new int[2];
		int b[]=new int[2];
		int t=scanner.nextInt();
		while(t-->0) {
			for (int i = 0; i < b.length; i++) {
				a[i]=scanner.nextInt();
			}
			for (int i = 0; i < b.length; i++) {
				b[i]=scanner.nextInt();
			}
			int count=0; //a获胜的所有情况数
			count+=f(a[0],a[1],b[0],b[1]);
			count+=f(a[0],a[1],b[1],b[0]);
			System.out.println(count);
		}

	}
	public static int f(int a1,int a2,int b1,int b2) {
		int scoreA=0;
		int scoreB=0;
		if(a1>b1) {
			scoreA++;
		}else if(a1<b1){
			scoreB++;
		}
		if(a2>b2) {
			scoreA++;
		}else if(a2<b2){
			scoreB++;
		}
		return scoreA>scoreB?2:0;
	}

}

这一题要分两种情况来讨论,每一种情况又有两有可能。首先是a[0]对战b[0],a[1]对战b[1],根据获胜情况返回2或者0,还有一种就是a[0]对战b[1],a[1]对战b[0],同理

全部评论

相关推荐

04-15 20:51
门头沟学院 Java
纳斯卡可:把名字改一下吧 千万级用户你真测过吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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