CF143B.Help Kingdom of Far Far Away 2
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
For some time the program of rounding numbers that had been developed by the Codeforces participants during one of the previous rounds, helped the citizens of Far Far Away to convert numbers into a more easily readable format. However, as time went by, the economy of the Far Far Away developed and the scale of operations grew. So the King ordered to found the Bank of Far Far Away and very soon even the rounding didn't help to quickly determine even the order of the numbers involved in operations. Besides, rounding a number to an integer wasn't very convenient as a bank needed to operate with all numbers with accuracy of up to 0.01, and not up to an integer.
The King issued yet another order: to introduce financial format to represent numbers denoting amounts of money. The formal rules of storing a number in the financial format are as follows:
- A number contains the integer part and the fractional part. The two parts are separated with a character "." (decimal point).
- To make digits in the integer part of a number easier to read, they are split into groups of three digits, starting from the least significant ones. The groups are separated with the character "," (comma). For example, if the integer part of a number equals 12345678, then it will be stored in the financial format as 12,345,678
- In the financial format a number's fractional part should contain exactly two digits. So, if the initial number (the number that is converted into the financial format) contains less than two digits in the fractional part (or contains no digits at all), it is complemented with zeros until its length equals 2. If the fractional part contains more than two digits, the extra digits are simply discarded (they are not rounded: see sample tests).
- When a number is stored in the financial format, the minus sign is not written. Instead, if the initial number had the minus sign, the result is written in round brackets.
- Please keep in mind that the bank of Far Far Away operates using an exotic foreign currency — snakes (),that′swhyrightbeforethenumberinthefinancialformatweshouldputthesign"". If the number should be written in the brackets, then the snake sign should also be inside the brackets.
For example, by the above given rules number 2012 will be stored in the financial format as "$2,012.00" and number -12345678.9 will be stored as "($12,345,678.90)".
The merchants of Far Far Away visited you again and expressed much hope that you supply them with the program that can convert arbitrary numbers to the financial format. Can you help them?
一段时间以来,Codeforces 参赛者在之前某一轮比赛中开发的四舍五入程序,曾帮助遥远国度(Far Far Away)的市民将数字转换为更易读的格式。然而,随着时间推移,遥远国度的经济不断发展,业务规模日益扩大。因此,国王下令成立“遥远国度银行”(Bank of Far Far Away),很快,即使是四舍五入也无法快速判断参与业务运算的数字的大致数量级。此外,将数字四舍五入到整数对银行而言并不方便,因为银行需要以精确到 0.01 的精度处理所有数字,而非仅精确到整数。
国王又下达了一项新命令:引入财务格式(financial format)来表示金额数字。将一个数字以财务格式存储的正式规则如下:
- 一个数字包含整数部分和小数部分,两部分之间用字符
.(小数点)分隔。 - 为了便于阅读数字的整数部分,需从最低位(个位)起,每三位数字划分为一组,组与组之间用字符
,(逗号)分隔。例如,若一个数字的整数部分为12345678,则其财务格式表示为12,345,678。 - 在财务格式中,数字的小数部分必须恰好包含两位数字。因此,若原始数字(即待转换为财务格式的数字)的小数部分不足两位(或根本没有小数位),则在其末尾补零,直至长度为 2;若小数部分超过两位,则直接截断多余位数(不进行四舍五入:参见样例测试)。
- 当一个数字以财务格式存储时,不写负号。取而代之的是:若原始数字带有负号,则最终结果应写在圆括号
()内。 - 请注意,遥远国度银行使用一种奇特的外币——“蛇币”(snakes,符号为
$)。因此,在财务格式的数字前面须添加$符号;若该数字需写在括号内,则$符号也必须置于括号内部。
例如,根据上述规则,数字 2012 将以财务格式表示为 "$2,012.00",而数字 -12345678.9 将表示为 "($12,345,678.90)"。
遥远国度的商人们再次造访了你,并满怀希望地请求你为他们提供一款能将任意数字转换为财务格式的程序。你能帮他们吗?
输入格式
The input contains a number that needs to be converted into financial format. The number's notation length does not exceed 100 characters, including (possible) signs "-" (minus) and "." (decimal point). The number's notation is correct, that is:
- The number's notation only contains characters from the set {"0" – "9", "-", "."}.
- The decimal point (if it is present) is unique and is preceded and followed by a non-zero quantity on decimal digits
- A number cannot start with digit 0, except for a case when its whole integer part equals zero (in this case the integer parts is guaranteed to be a single zero: "0").
- The minus sign (if it is present) is unique and stands in the very beginning of the number's notation
- If a number is identically equal to 0 (that is, if it is written as, for example, "0" or "0.000"), than it is not preceded by the minus sign.
- The input data contains no spaces.
- The number's notation contains at least one decimal digit.
输入包含一个需要转换为财务格式的数字。该数字的表示长度不超过 100 个字符,包括(可能存在的)符号“-”(负号)和“.”(小数点)。该数字的表示是合法的,即满足以下条件:
- 该数字的表示仅包含字符集 {“0”–“9”, “-”, “.”} 中的字符;
- 小数点(若存在)是唯一的,且其前后均至少有一位小数位(即小数点前、后均非空);
- 数字不能以数字“0”开头,除非其整数部分整体等于零(此时整数部分保证仅为单个“0”:“0”);
- 负号(若存在)是唯一的,且位于数字表示的最开头;
- 若该数字恒等于 0(例如写作“0”或“0.000”),则其前面不得有负号;
- 输入数据中不含空格;
- 该数字的表示中至少包含一位小数位。
输出格式
Print the number given in the input in the financial format by the rules described in the problem statement.
按照题目描述的规则,以财务格式输出输入中给出的数字。
输入输出样例
输入#1
2012
输出#1
$2,012.00
输入#2
0.000
输出#2
$0.00
输入#3
-0.00987654321
输出#3
($0.00)
输入#4
-12345678.9
输出#4
($12,345,678.90)
说明/提示
Pay attention to the second and third sample tests. They show that the sign of a number in the financial format (and consequently, the presence or absence of brackets) is determined solely by the sign of the initial number. It does not depend on the sign of the number you got after translating the number to the financial format.
请注意第二和第三个样例测试。它们表明,财务格式中一个数字的符号(以及相应地,括号的存在或缺失)仅由原始数字的符号决定,而与将该数字转换为财务格式后所得数字的符号无关。
输入解题思路,AI测评打分。不知道怎么写?