傳送門
https://pintia.cn/problem-sets/994805260223102976/problems/994805277847568384
題目
劃拳是古老中國酒文化的一個有趣的組成部分诗眨。酒桌上兩人劃拳的方法為:每人口中喊出一個數(shù)字拧篮,同時用手比劃出一個數(shù)字。如果誰比劃出的數(shù)字正好等于兩人喊出的數(shù)字之和入宦,誰就贏了九巡,輸家罰一杯酒图贸。兩人同贏或兩人同輸則繼續(xù)下一輪,直到唯一的贏家出現(xiàn)冕广。
下面給出甲疏日、乙兩人的劃拳記錄,請你統(tǒng)計他們最后分別喝了多少杯酒撒汉。
輸入格式:
輸入第一行先給出一個正整數(shù)N(<=100)沟优,隨后N行,每行給出一輪劃拳的記錄睬辐,格式為:
甲喊 甲劃 乙喊 乙劃
其中“喊”是喊出的數(shù)字挠阁,“劃”是劃出的數(shù)字,均為不超過100的正整數(shù)(兩只手一起劃)溯饵。
輸出格式:
在一行中先后輸出甲侵俗、乙兩人喝酒的杯數(shù),其間以一個空格分隔丰刊。
輸入樣例:
5
8 10 9 12
5 10 5 10
3 8 5 12
12 18 1 13
4 16 12 15
輸出樣例:
1 2
分析
這道題難度不大隘谣,每次輸入后判斷下是否相等就好了,注意:甲贏的條件是在乙沒贏的情況下啄巧,同理乙贏也是一樣寻歧。
源代碼
//C/C++實現(xiàn)
#include <iostream>
using namespace std;
int main(){
int n;
scanf("%d", &n);
int jiahan, jiahua, yihan, yihua, jiaying = 0, yiying = 0;
for(int i = 0; i < n; ++i){
scanf("%d %d %d %d", &jiahan, &jiahua, &yihan, &yihua);
int sum = jiahan + yihan;
if(jiahua == sum && yihua != sum){
++jiaying;
}
else if(jiahua != sum && yihua == sum){
++yiying;
}
}
printf("%d %d\n", yiying, jiaying);
return 0;
}
//Java實現(xiàn)
import java.util.Scanner;
public class Main{
public static void main(String []args){
Scanner scanner = new Scanner(System.in);
int round = scanner.nextInt();
int Awin = 0, Bwin = 0;
if(round > 0 && round <=100){
for(int i=0;i<round;i++){
int Acall = scanner.nextInt();
if(!validate(Acall))
System.exit(0);
int Agesture = scanner.nextInt();
if(!validate(Agesture))
System.exit(0);
int Bcall = scanner.nextInt();
if(!validate(Bcall))
System.exit(0);
int Bgesture = scanner.nextInt();
if(!validate(Bgesture))
System.exit(0);
if((Agesture == Acall + Bcall) && (Bgesture != Acall + Bcall)){
Awin ++;
}
else if((Bgesture == Acall + Bcall) && (Agesture != Acall + Bcall)){
Bwin ++;
}
}
System.out.println(Bwin+" "+Awin);
}
}
private static boolean validate(int i){
if(i > 0 && i <=100 ) return true;
else return false;
}
}