1046. 划拳(15) [模拟]

1046. 划拳(15) [模拟]
划拳是古⽼中国酒⽂化的⼀个有趣的组成部分。酒桌上两⼈划拳的⽅法为:每⼈⼝中喊出⼀个数字,
同时⽤⼿⽐划出⼀个数字。如果谁⽐划出的数字正好等于两⼈喊出的数字之和,谁就赢了,输家罚⼀
杯酒。两⼈同赢或两⼈同输则继续下⼀轮,直到唯⼀的赢家出现。
下⾯给出甲、⼄两⼈的划拳记录,请你统计他们最后分别喝了多少杯酒。
输⼊格式:
输⼊第⼀⾏先给出⼀个正整数N(<=100),随后N⾏,每⾏给出⼀轮划拳的记录,格式为:
甲喊 甲划 ⼄喊 ⼄划
其中“喊”是喊出的数字,“划”是划出的数字,均为不超过100的正整数(两只⼿⼀起划)。
输出格式:

在⼀⾏中先后输出甲、⼄两⼈喝酒的杯数,其间以⼀个空格分隔。
输⼊样例:
5
8 10 9 12
5 10 5 10
3 8 5 12
12 18 1 13
4 16 12 15
输出样例:
1在⼀⾏中先后输出甲、⼄两⼈喝酒的杯数,其间以⼀个空格分隔。
输⼊样例:
5
8 10 9 12
5 10 5 10
3 8 5 12
12 18 1 13
4 16 12 15
输出样例:

 

解:这题。。。太简单了,康康代码即可~

#include <cstdio>
#include <cstring>
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
using namespace std;

struct peo{
	int x;   //喊
	int y;   //划
	int sum;
}a[101], b[101], s[101];

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		scanf("%d%d%d%d", &a[i].x, &a[i].y, &b[i].x, &b[i].y);
		s[i].sum = a[i].x + b[i].x;
	}
	int cntj = 0, cnty = 0;
	for (int i = 0; i < n; i++) {
		if (a[i].y == s[i].sum && b[i].y != s[i].sum)
			cnty++;  //甲赢了,乙喝
		if (b[i].y == s[i].sum && a[i].y != s[i].sum)
			cntj++;
	}
	cout << cntj << " " << cnty;
	return 0;
}

大佬code

#include <iostream>
using namespace std;
int main() {
	int n, jia = 0, yi = 0, jiahan, jiahua, yihan, yihua, sum;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> jiahan >> jiahua >> yihan >> yihua;
		sum = jiahan + yihan;
		if (sum == jiahua && sum != yihua)
			yi++;
		if (sum != jiahua && sum == yihua)
			jia++;
	}
	cout << jia << " " << yi;
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值