CF1297A.Likes Display

普及/提高-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Polycarp is working on the implementation of displaying likes on the Codehorses social network. The number of likes should be displayed in a format that will be easy to read by users. It was decided that for large numbers of likes the format should be like 123K (one hundred twenty-three thousand) or like 56M (fifty-six million).

The following displaying strategy has been approved:

  • the number will be displayed either as an integer number from 0 to 999, or as a positive integer number of thousands (from 1K to 999K), or as a positive integer number of millions (from 1M on),
  • the specified exact number of likes nn when displaying should be rounded to the nearest view from the case above (if rounding is ambiguous, it must be rounded up): for example, 17851785 should be rounded to 2K instead of 1K, 45000004500000 should be rounded to 5M.

Help Polycarp implement this part of the functionality: for a given non-negative integer number of likes nn, print its view in the Codehorses interface.

Polycarp 正在为 Codehorses 社交网络实现点赞数的显示功能。点赞数的显示格式应便于用户阅读。经决定,对于较大的点赞数,应采用类似 123K(十二万三千)或 56M(五百六十万)的格式。

以下显示策略已获批准:

  • 点赞数将显示为以下三者之一:
    • 一个介于 00 到 999999 之间的整数;
    • 一个介于 1K1\text{K} 到 999K999\text{K} 之间的正整数千位数(即以千为单位的整数);
    • 一个从 1M1\text{M} 开始的正整数百万位数(即以百万为单位的整数);
  • 给定确切的点赞数 nn,在显示时应四舍五入到上述三种形式中最接近的一种(若四舍五入结果存在歧义,则向上取整):例如,17851785 应四舍五入为 2K 而非 1K,45000004500000 应四舍五入为 5M。

请帮助 Polycarp 实现该功能模块:对给定的非负整数点赞数 nn,输出其在 Codehorses 界面中的显示形式。

输入格式

The first line contains an integer tt (1≤t≤10001 \le t \le 1000) — the number of test cases in the input. The following are descriptions of the tt input test cases, one per line.

The description of each test case consists of a single line that contains a non-negative integer nn (0≤n≤2⋅1090 \le n \le 2\cdot10^9) — the number of likes.

第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000)—— 输入中测试用例的数量。接下来是 tt 个输入测试用例的描述,每个测试用例占一行。

每个测试用例的描述由一行组成,其中包含一个非负整数 nn(0≤n≤2⋅1090 \le n \le 2\cdot10^9)—— 点赞数量。

输出格式

Print tt answers to the given test cases in the order from the input. Each printed value must have one of the following types:

  • either an integer from 0 to 999 which corresponds just to the number of likes,
  • or a number of thousands from 1K to 999K,
  • or a number of millions from 1M to 2000M.

The answer is equal to a view which is the closest (by difference) to the given number nn. If this rounding is ambiguous, then round answer up (to a greater value).

按输入顺序输出 tt 个测试用例的答案。每个输出值必须属于以下类型之一:

  • 一个从 0 到 999 的整数,直接表示点赞数;
  • 一个以千为单位的数,范围为 1K 到 999K;
  • 一个以百万为单位的数,范围为 1M 到 2000M。

答案等于与给定数字 nn 最接近(即差值最小)的表示形式。若该舍入存在歧义(即有两个等距的候选值),则向上舍入(取较大的值)。

输入输出样例

  • 输入#1

    9
    999
    123
    0
    1782
    31415926
    1500
    999999
    35499710
    2000000000

    输出#1

    999
    123
    0
    2K
    31M
    2K
    1M
    35M
    2000M

说明/提示

Let's describe some test cases:

  • 17821782 can be displayed either as 1K or as 2K but 2K is the nearest view;
  • 15001500 have same difference with 1K and 2K so it should be rounded up;
  • 999999999999 should be displayed as 1M since it's closer to it than to 999K.

我们来描述一些测试用例:

  • 17821782 可以显示为 1K 或 2K,但 2K 是更近的表示;
  • 15001500 与 1K 和 2K 的差值相同,因此应向上取整;
  • 999999999999 应显示为 1M,因为它比 999K 更接近 1M。

输入解题思路,AI测评打分。不知道怎么写?

首页