{ }codelper
reading numbersiterating listsmax / mininteger divisionP0003

Score statistics

The first line gives the number of students n, and the second line gives n scores.
Print the highest score, the lowest score and the average (rounded down) on one line, separated by spaces.

Input
1 ≤ n ≤ 1,000, 0 ≤ score ≤ 100
Output
max min average
Example 1 · stdin
3
70 85 90
stdout
90 70 81
main.py
Input (stdin)

When you run, these lines are fed to input()/stdin in order (the program doesn't stop to ask).

$ Ready

Open this on a computer to write and run code. On mobile you can read the problem and the solutions.

In other languagesShow solutions by language · 8 languages

Integer division: in C-family languages int/int already rounds down, Python uses //, and JavaScript, TypeScript and Craykon have a single number type so they need an explicit floor (Math.floor / Mathf.Floor).

Pythonmain.py · 3 lines
n = int(input())scores = list(map(int, input().split()))print(max(scores), min(scores), sum(scores) // n)
JavaScriptmain.js · 3 lines
const [n, ...scores] = require("fs").readFileSync(0, "utf8").trim().split(/\s+/).map(Number);const sum = scores.reduce((a, b) => a + b, 0);console.log(Math.max(...scores), Math.min(...scores), Math.floor(sum / n));
TypeScriptmain.ts · 4 lines
import { readFileSync } from "node:fs";const [n, ...scores]: number[] = readFileSync(0, "utf8").trim().split(/\s+/).map(Number);const sum: number = scores.reduce((a, b) => a + b, 0);console.log(Math.max(...scores), Math.min(...scores), Math.floor(sum / n));
JavaMain.java · 16 lines
import java.util.Scanner; public class Main {    public static void main(String[] args) {        Scanner sc = new Scanner(System.in);        int n = sc.nextInt();        int max = Integer.MIN_VALUE, min = Integer.MAX_VALUE, sum = 0;        for (int i = 0; i < n; i++) {            int s = sc.nextInt();            max = Math.max(max, s);            min = Math.min(min, s);            sum += s;        }        System.out.println(max + " " + min + " " + sum / n);    }}
C#Main.cs · 12 lines
using System;using System.Linq; class Program{    static void Main()    {        int n = int.Parse(Console.ReadLine());        int[] s = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();        Console.WriteLine($"{s.Max()} {s.Min()} {s.Sum() / n}");    }}
C++main.cpp · 14 lines
#include <algorithm>#include <iostream>#include <numeric>#include <vector> int main() {    int n;    std::cin >> n;    std::vector<int> s(n);    for (int& x : s) std::cin >> x;    int sum = std::accumulate(s.begin(), s.end(), 0);    std::cout << *std::max_element(s.begin(), s.end()) << ' '              << *std::min_element(s.begin(), s.end()) << ' ' << sum / n << '\n';}
Cmain.c · 14 lines
#include <stdio.h> int main(void) {    int n, s, max = -1, min = 101, sum = 0;    scanf("%d", &n);    for (int i = 0; i < n; i++) {        scanf("%d", &s);        if (s > max) max = s;        if (s < min) min = s;        sum += s;    }    printf("%d %d %d\n", max, min, sum / n);    return 0;}
Craykonmain.cray · 12 lines
n = Console.ReadLine().ToNumber();점수들 = Console.ReadNumbers();최고 = 점수들[0];최저 = 점수들[0];합 = 0;foreach (점수 in 점수들){    최고 = Mathf.Max(최고, 점수);    최저 = Mathf.Min(최저, 점수);    합 += 점수;}Console.WriteLine(최고 + " " + 최저 + " " + Mathf.Floor(합 / n));