231A. Team – CodeForces Solution

Solution in__

Python:


n = int(input())  # Reading the number of problems
count = 0

for _ in range(n):
    votes = list(map(int, input().split()))
    if sum(votes) >= 2:  # At least 2 friends should be sure about the solution
        count += 1

print(count)


Python

C#:


using System;

class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int count = 0;

        for (int i = 0; i < n; i++)
        {
            string[] votes = Console.ReadLine().Split();
            int sureCount = int.Parse(votes[0]) + int.Parse(votes[1]) + int.Parse(votes[2]);
            if (sureCount >= 2)
            {
                count++;
            }
        }

        Console.WriteLine(count);
    }
}


C#

Go:


package main

import (
    "fmt"
)

func main() {
    var n, count int
    fmt.Scan(&n)

    for i := 0; i < n; i++ {
        var a, b, c int
        fmt.Scan(&a, &b, &c)
        if a+b+c >= 2 {
            count++
        }
    }

    fmt.Println(count)
}

Go

Ruby:


n = gets.to_i
count = 0

n.times do
  votes = gets.split.map(&:to_i)
  count += 1 if votes.sum >= 2
end

puts count


Ruby

Rust:


use std::io;

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let n: usize = input.trim().parse().unwrap();
    
    let mut count = 0;
    for _ in 0..n {
        let mut input = String::new();
        io::stdin().read_line(&mut input).unwrap();
        let votes: Vec<i32> = input.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
        if votes.iter().sum::<i32>() >= 2 {
            count += 1;
        }
    }
    
    println!("{}", count);
}


Rust

Kotlin:


fun main() {
    val n = readLine()!!.toInt()
    var count = 0

    repeat(n) {
        val votes = readLine()!!.split(" ").map { it.toInt() }
        if (votes.sum() >= 2) {
            count++
        }
    }

    println(count)
}

Kotlin

Explanation

  1. Each solution starts by reading the number of problems n.
  2. For each problem, the votes from Petya, Vasya, and Tonya (either 0 or 1) are read.
  3. The sum of the votes is calculated, and if the sum is 2 or more, it means at least two of the friends are sure, and the problem will be solved.
  4. Finally, the total count of problems they will solve is printed.

This method works efficiently given the constraints (1 ≤ n ≤ 1000).

April 7, 2024