Algorithm
Problem Name: 2 AD-HOC - beecrowd | 1715
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1715
Handball
By Ricardo Anido Brazil
Timelimit: 1
Frustrated and disappointed with the results of its football team, the Super Brazilian Club (SBC) decided to invest in the handball team. In order to better rate the players, the coaches would like to analyse their regularity. Specifically, they are interested in knowing how many players scored goals in all matches.
As the data volume is very big, they would like to have a computer program to do this counting.
Input
The input contains several test cases. The first line of a test case contains two integers N and M (1 ≤ N ≤ 100 and 1 ≤ M ≤ 100) indicating, respectively, the number of players and the number of matches. Each one of the next N lines describes the performance of one player: the i-th line contains M integers Xj (0 ≤ Xj ≤ 100, for 1 ≤ j ≤ M ), giving the number of goals that the i-th player scored in each match.
Output
For each test case in the input your program must output one line, containing one integer, the number of players that scored goals in all matches!
Sample Input | Sample Output |
5 3 0 0 0 1 0 5 0 0 0 0 1 2 1 1 0 |
0 |
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include <stdio.h>
#define true 1
#define false 0
int main(void) {
int n, m, k = 0, e, i, j;
int z;
scanf("%d %d", &n, &m);
for (i = 0; i < n; ++i) {
z = false;
for (j = 0; j < m; ++j) {
scanf("%d", &e);
if (!e) z = true;
}
if (!z) ++k;
}
printf("%d\n", k);
return 0;
}
Copy The Code &
Try With Live Editor
Input
0 0 0
1 0 5
0 0 0
0 1 2
1 1 0
#2 Code Example with C++ Programming
Code -
C++ Programming
#include <iostream>
using namespace std;
int main(void) {
int n, m, k = 0, e, i, j;
bool z;
cin >> n >> m;
for (i = 0; i < n; ++i) {
z = false;
for (j = 0; j < m; ++j) {
cin >> e;
if (!e) z = true;
}
if (!z) ++k;
}
cout << k << endl;
return 0;
}
Copy The Code &
Try With Live Editor
Input
0 0 0
1 0 5
0 0 0
0 1 2
1 1 0
#3 Code Example with Javascript Programming
Code -
Javascript Programming
const { readFileSync } = require("node:fs")
const [[N, M], ...input] = readFileSync("/dev/stdin", "utf8")
.split("\n", 101)
.map((line) => line.split(" ", 100).map(value => Number.parseInt(value, 10)))
console.log(
input
.filter((handballPlayerStatics) => handballPlayerStatics.every(points => points > 0))
.length
)
Copy The Code &
Try With Live Editor
Input
0 0 0
1 0 5
0 0 0
0 1 2
1 1 0