跳到正文

个人记录

A. 【六月份 -- 基础语法组】-- T1 -- 四舍五入

zhangyuqiTAT约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年5月16日
收录
2025年12月12日
更新
2026年11月21日
篇幅
约 1 分钟

版本

  1. v1当前

https://cspjs.online/contest/699/problem/1

C++
#include <bits/stdc++.h>
using namespace std;
int main() {
    freopen("round.in", "r", stdin);
    freopen("round.out", "w", stdout);
    long long t, n;
    cin >> t;
    while (t--) {
        cin >> n;
        long long ans = 0;
        long long k = 1;
        while (n) {
            long long a = n % 10;
            n /= 10;
            if (a >= 5) {
                n++;
                ans = 0;
            } else {
                ans += k * a;
            }
            k *= 10;
        }
        cout << ans << endl;
    }
    return 0;
}
原文