Sorry, your browser cannot access this site
This page requires browser support (enable) JavaScript
Learn more >

题目描述

image-20250325184315859

一共有 n 道题目,而对于每道题,他们会选择是否去做这题:只有当三个人中至少有两个人对这题有把握时,他们才会决定去做。

思路

直接计算每行的和是否大于等于2。

代码

Python

1
2
3
4
5
6
7
8
9
n = int(input())  
count = 0

for _ in range(n):
a, b, c = map(int, input().split())
if a + b + c >= 2:
count += 1

print(count)

C

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <stdio.h>

int main() {
int n, a, b, c;
int count = 0;
scanf("%d", &n);

for (int i = 0; i < n; i++) {
scanf("%d %d %d", &a, &b, &c);
if (a + b + c >= 2) {
count++;
}
}

printf("%d\n", count);
return 0;
}

C++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

using namespace std;

int main(){
int n;
cin >> n;
int a,b,c;
int count=0;
for( int i=0; i < n; i++){
cin >> a >> b >> c;
if(a+b+c >1){
count +=1;
}
}
cout << count;
return 0;
}