The first line gives the count n, and each of the next n lines gives a number with exactly one digit after the decimal point. Round each number to the nearest integer and print one per line. When the fractional part is exactly 0.5, so the number is halfway between two integers, go to the even one (banker's rounding): 0.5 → 0, 1.5 → 2, 2.5 → 2, -0.5 → 0, -1.5 → -2, -2.5 → -2. Otherwise go to the nearer one (2.4 → 2, -2.6 → -3). When the result is zero print "0", never "-0".
Input
1 ≤ n ≤ 1,000, -1,000,000.0 ≤ number ≤ 1,000,000.0, every number is written with one decimal digit (e.g. 7.0, -0.4). "-0.0" never appears.
Output
n lines, one integer each
Example 1 · stdin
6
2.5
3.5
-2.5
-0.4
1.6
7.0
stdout
2
4
-2
0
2
7
main.py
Error List00F8 ↓ · ⇧F8 ↑
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
The 'exactly half' rule differs by language. Ties to even by default: Python round(x), C# Math.Round(x) (default MidpointRounding.ToEven), Java Math.rint(x), C/C++ rint/llrint/nearbyint (default rounding mode). Away from zero: C/C++ round/llround, Craykon Mathf.Round. Toward +∞: Java Math.round (= floor(x + 0.5), 2.5 → 3) and JS/TS Math.round (2.5 → 3, -2.5 → -2). JS/TS and Craykon have no ties-to-even function, so build it: floor, then check whether the remainder is 0.5 — for one-decimal inputs 0.5 is exact in binary, so x - floor(x) == 0.5 is reliable. The second trap is -0. Rounding -0.4 gives the double -0, and JS console.log(-0), C printf("%.0f") and C# Console.WriteLine(Math.Round(-0.4)) (since .NET Core 3.0) print "-0". In C#, Java and C convert to an integer (long) before printing; in JS/TS and Craykon add + 0, which turns -0 into 0. Python round(x) already returns an int, so it is fine.
Pythonmain.py · 4 lines
n = int(input())for _ in range(n): # round()는 딱 반이면 짝수 쪽으로 간다(2.5 → 2, 3.5 → 4). 돌려주는 값도 int라 -0이 없다 print(round(float(input())))
JavaScriptmain.js · 13 lines
const [n, ...xs] = require("fs").readFileSync(0, "utf8").trim().split(/\s+/).map(Number);// JS에는 짝수 쪽 반올림이 없다. Math.round는 딱 반이면 +∞ 쪽(2.5 → 3, -2.5 → -2)function roundHalfEven(x) { const f = Math.floor(x); const diff = x - f; // 소수 한 자리라 0.5는 정확히 0.5로 나온다 if (diff < 0.5) return f; if (diff > 0.5) return f + 1; return f % 2 === 0 ? f : f + 1;}// f + 0으로 -0을 0으로 (console.log(-0)은 "-0"을 찍는다)console.log(xs.map((x) => roundHalfEven(x) + 0).join("\n"));
TypeScriptmain.ts · 14 lines
import { readFileSync } from "node:fs";const [n, ...xs]: number[] = readFileSync(0, "utf8").trim().split(/\s+/).map(Number);// TS에도 짝수 쪽 반올림이 없다. Math.round는 딱 반이면 +∞ 쪽(2.5 → 3, -2.5 → -2)function roundHalfEven(x: number): number { const f = Math.floor(x); const diff = x - f; // 소수 한 자리라 0.5는 정확히 0.5로 나온다 if (diff < 0.5) return f; if (diff > 0.5) return f + 1; return f % 2 === 0 ? f : f + 1;}// + 0으로 -0을 0으로 (console.log(-0)은 "-0"을 찍는다)console.log(xs.map((x) => roundHalfEven(x) + 0).join("\n"));
JavaMain.java · 17 lines
import java.io.BufferedReader;import java.io.InputStreamReader;public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine().trim()); StringBuilder out = new StringBuilder(); for (int i = 0; i < n; i++) { double x = Double.parseDouble(br.readLine().trim()); // Math.rint는 딱 반이면 짝수 쪽. Math.round는 floor(x + 0.5)라 2.5 → 3 // long으로 바꾸면 -0.0도 0이 된다 out.append((long) Math.rint(x)).append('\n'); } System.out.print(out); }}
C#Main.cs · 17 lines
using System;using System.Globalization;class Program{ static void Main() { int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { double x = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); // Math.Round의 기본은 짝수 쪽(MidpointRounding.ToEven). // 돌려주는 값이 double이라 -0.4 → -0이 "-0"으로 찍히니 long으로 바꾼다 Console.WriteLine((long)Math.Round(x)); } }}
C++main.cpp · 15 lines
#include <cmath>#include <iostream>int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; double x; std::cin >> n; for (int i = 0; i < n; i++) { std::cin >> x; // std::llrint는 기본 반올림 방식(딱 반이면 짝수 쪽). std::round는 0에서 먼 쪽 std::cout << std::llrint(x) << '\n'; }}
Cmain.c · 15 lines
#include <math.h>#include <stdio.h>int main(void) { int n; double x; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%lf", &x); /* llrint는 지금 반올림 방식(기본: 딱 반이면 짝수 쪽)을 따른다. round()는 0에서 먼 쪽이라 2.5 → 3 */ printf("%lld\n", llrint(x)); } return 0;}
Craykonmain.cray · 21 lines
// 수학.반올림은 딱 반이면 0에서 먼 쪽(2.5 → 3)이라 짝수 쪽 반올림은 직접 만든다짝수쪽반올림(x){ f = Mathf.Floor(x); 차 = x - f; if (차 < 0.5) { return f; } if (차 > 0.5) { return f + 1; } return f % 2 == 0 ? f : f + 1;}n = Console.ReadLine().ToNumber();for (i = 0; i < n; i++){ Console.WriteLine(짝수쪽반올림(Console.ReadLine().ToNumber()) + 0);}