列表

详情


NC223923. BPresidentialElection

描述

Presidential election is coming up (November). In 2016, Clinton won the “majority” votes but Trump ended up with more “electoral” votes and won the race. (As a reminder, if a candidate receives more votes in a state, that candidate wins all the electoral votes for that state, i.e., electoral votes for a state are not divided proportionally based on the votes received by each candidate in that state.)

The Problem:

Election is in less than two months so let’s predict the outcome! Given the voting data for each state, determine who wins the majority votes and who wins the electoral votes.

输入描述

The first input line contains an integer, n (1 ≤ n ≤ 50), indicating the number of states. Each of the nextninput lines contains three integers, providing voting data for a state:e(1 ≤e≤ 100), indicating electoral votes for the state,v1 (0 ≤v1 ≤ 1000), indicating votes for the first candidate, andv2 (0 ≤v2 ≤ 1000;v2 ≠v1), indicating votes for the second candidate.

输出描述

Print 1 (one) if the first candidate wins both the majority votes and the electoral votes. Print 2 (two) if the second candidate wins both the majority votes and the electoral votes. Print 0 (zero) for all the other cases. Assume that if the total majority votes for the two candidates tie, neither one wins the majority. Similarly, if the total electoral votes for the two candidates tie, neither one wins the electoral.

示例1

输入:

3 
5 10 50 
15 30 60
10 25 15

输出:

2

示例2

输入:

3 
5 48 50 
15 57 60
10 25 15

输出:

0

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++ 解法, 执行用时: 5ms, 内存消耗: 488K, 提交时间: 2021-08-17 12:08:10

#include <cstdio>
int n, e, sum1, sum2, s1, s2, a, b;
int main()
{
	scanf("%d", &n);
	while(n--)
	{
		scanf("%d%d%d", &e, &a, &b);
		if(a>b) sum1+=e;
		else sum2+=e;
		s1+=a, s2+=b;
	}
	printf("%d\n", (s1<s2&&sum1<sum2)?2:(s1>s2&&sum1>sum2)?1:0);
	return 0;
}

上一题