CodeForces 143B - Help Kingdom of Far Far Away 2(字符串模拟)

手把手教你用CH340E烧录器玩转PY32系列芯片(附固件升级教程) 本文详细介绍了如何使用CH340E烧录器对PY32系列芯片进行烧录和固件升级。从驱动安装、硬件连接到固件管理,再到高级烧录配置和跨平台工作流优化,提供了全面的指南和实用技巧,帮助开发者快速掌握PY32芯片的烧录技术。 阅读详情

B. Help Kingdom of Far Far Away 2
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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's why right before the number in the financial format we should put the sign "$". 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?

Input

The input contains a number that needs to be converted into financial format. The number's notation length does not exceed 100characters, 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.

Output

Print the number given in the input in the financial format by the rules described in the problem statement.

Sample test(s)
input
2012
output
$2,012.00
input
0.000
output
$0.00
input
-0.00987654321
output
($0.00)
input
-12345678.9
output
($12,345,678.90)
Note

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.



===================================

字符串模拟


#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>

using namespace std;

int main()
{
    char str[111];
    cin>>str;
    int len=strlen(str),p=0;
    for(int i=0; i<len; i++)
    {
        if(str[i]=='.') p=i;//小数点位置
    }
    if(str[0]!='-')//正数
    {
        cout<<"$";
        if(p)
        {
            if(len-p==2) str[p+2]='0';
            int i=0;
            if(p%3)
            {
                for(i=0; i<p%3; i++)
                {
                    cout<<str[i];
                }
                if(p>=3) cout<<",";
            }
            for(int k=0;i<p;i++,k++)
            {
                if(k%3==0&&k) cout<<",";
                cout<<str[i];
            }
            cout<<str[i]<<str[i+1]<<str[i+2]<<endl;
        }
        else
        {
            int i=0;
            if(len%3)
            {
                for(i=0; i<len%3; i++)
                {
                    cout<<str[i];
                }
                if(len>3) cout<<",";
            }
            for(int k=0;i<len;i++,k++)
            {
                if(k%3==0&&k) cout<<",";
                cout<<str[i];
            }
            cout<<".00"<<endl;
        }
    }
    else//负数
    {
        cout<<"($";
        if(p)
        {
            if(len-p==2) str[p+2]='0';
            int i=1;
            if((p-1)%3)
            {
                for(i=1; i<=(p-1)%3; i++)
                {
                    cout<<str[i];
                }
                if(p>4) cout<<",";
            }
            for(int k=0;i<p;i++,k++)
            {
                if(k%3==0&&k) cout<<",";
                cout<<str[i];
            }
            cout<<str[i]<<str[i+1]<<str[i+2]<<")"<<endl;
        }
        else
        {
            int i=1;
            if((len-1)%3)
            {
                for(i=1; i<=(len-1)%3; i++)
                {
                    cout<<str[i];
                }
                if(len>4) cout<<",";
            }
            for(int k=0;i<len;i++,k++)
            {
                if(k%3==0&&k) cout<<",";
                cout<<str[i];
            }
            cout<<".00)"<<endl;
        }
    }
    return 0;
}


Shortest Path of the King CodeForces #3A 题解[C++] 题目来源 http://codeforces.com/contest/3/problem/A 题意解析 The king is left alone on the chessboard. In spite of this loneliness, he doesn’t lose heart, because he has business of national importance.... 阅读详情

相关推荐

STM32MP157+AD7606BSTZ四通道IEPE传感器采集方案实战(附完整电路图)

本文详细介绍了基于STM32MP157和AD7606BSTZ的四通道IEPE传感器采集方案,涵盖硬件电路设计、软件驱动开发及系统性能优化。通过精确的恒流源设计和同步采样技术,实现高精度振动信号采集,适用于工业振动监测等应用场景。

weixin_42713608的博客 702

Codeforces Round #102 (Div. 2)——B

B. Help Kingdom of Far Far Away 2 time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output For some time the program

Learn as if you were to live forever 499

知识图谱与人工智能本体论:构建机器认知的语义基石

本文探讨了知识图谱与人工智能本体论如何作为机器认知的语义基石,让AI从‘知道数据’迈向‘理解知识’。文章详细拆解了本体论的核心构件与构建方法,并阐述了从本体到知识图谱的实践路径,包括知识获取、融合、存储及推理应用,最终分析了其在智能搜索与专家系统等场景中带来的根本性重塑。

nginx7reverse的博客 910

训练赛35-A Help Victoria the Wise

Problem A: HelpVictoriatheWise Time Limit: 2 SecMemory Limit: 256 MB Submit: 15Solved: 5 [Submit][Status][Web Board] Description time limit per test 1 second memory limit per test 256 m...

来啦(#^.^#) 475

金融波动预测:GARCH模型实战解析与ARIMA对比

本文深入解析GARCH模型在金融波动预测中的实战应用,并与传统ARIMA模型进行对比。通过沪深300指数日收益率数据的案例分析,展示GARCH模型如何有效捕捉波动聚集效应,提升极端波动预测准确率。文章包含Python代码实现、参数解读及模型选择指南,为量化交易者提供实用的波动率建模解决方案。

weixin_29098367的博客 189

Kubernetes集群环境搭建与初始化

Kubernetes是Google开源的一个容器编排引擎,它支持自动化部署、大规模可伸缩、应用容器化管理。在生产环境中部署一个应用程序时,通常要部署该应用的多个实例以便对应用请求进行负载均衡。在Kubernetes中,我们可以创建多个容器,每个容器里面运行一个应用实例,然后通过内置的负载均衡策略,实现对这一组应用实例的管理、发现、访问,而这些细节都不需要运维人员去进行复杂的手工配置和处理。

m0_75254642的博客 1525

【题解】CodeForces-613D Kingdom and its Cities

话说之前自己都不相信自己能一遍打对,交都没交就傻傻地对拍了,所以文末附赠数据生成器 Problem CodeForces 未经润色的题目概要: 给定一棵有nnn个节点的树,qqq次询问,每次询问给kkk个点,求至少删除多少点,使得这kkk个点两两不属于同一联通块(n,q,∑k≤100000n,q,∑k≤100000n,q,\sum k\leq 100000) Solution 根据这类...

测试运算符 400

ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)解决办法

问题:ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: NO) 很久没用这台电脑的mysql了,今天需要连接数据库,启动数据库报错: ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: NO) 解决方法: 查阅资料后知道了,应该使用已知的用户名和密码登陆 mysql -u root -p 然而密

一个超会写Bug的程序猿的博客 43万+

A. Help Far Away Kingdom

A. Help Far Away Kingdom time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output In a far away kingdom lived the Ki

ecjtu_acm_菜鸟—鱼尾尾 969

V.PhyloMaker实战:从物种列表到维管束植物系统发育树的完整流程

本文详细介绍了使用V.PhyloMaker工具包,从物种列表快速构建维管束植物系统发育树的完整实战流程。内容涵盖R包安装、物种名标准化、核心函数phylo.maker的三种构建方案选择、结果树的可视化与导出,以及与picante包的联动分析,为生态学和生物地理学研究提供了高效解决方案。

weixin_29057237的博客 376

使用DCA1000和EVM板进行数据采集

目录 1. 准备工作 1.1 硬件 1.2 软件 2. 驱动安装 3. 设置静态IP地址 4. 采集数据 5. 采集的数据文件的格式 6. 数据采集存储的数据流 参考资料 1. 准备工作 1.1 硬件 EVM板,电源线(5V,>2.5A),USB线 DCA1000,电源线(5V,>2A),USB线,网线,60pin Samtec cable 1.2 软件 mmWave Studio Matlab Runtime Engine v8.5.1 将DCA1000和EVM板

qq_42235129的博客 1万+

沐枫NOI 7. Help Far Away Kingdom

In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there. Most

JUST CODE IT 539

微信小程序 - 下单账号和支付账号不一致,请核实后再支付(微信小程序或微信H5页面/微信公众号网页支付时报错:“下单账号和支付账号不一致,请核实后再支付”,买家微信支付时提示错误)详细排查和解决方案!

微信支付出现 “下单账号与支付账号不一致,请核实后再支付”微信小程序下单账号与支付账号不一致不让支付,微信公众号网页 微信H5页面JS-SDK支付时出现错误:下单账号和支付账号不一致,请核实后再支付,openId导致的微信中“下单账号和支付账号不一致”原因及解决办法,调用统一下单所传openId与实际支付用户的openId不一致,微信支付jssdk报错,检查了没有不一致依然报错怎么办,微信支付下单账号和支付账号不一致,请核实后再支付,微信支付功能用JSAPI支付,H5页面负责下单并支付jsapi,微信调起支

🏆 前端领域优质创作者 5330

codeforces 143B Help Kingdom of Far Far Away 2

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 mo

浮躁的人,终究一事无成! 1238

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

【题意string】#78 A. Help Far Away Kingdom

A. Help Far Away Kingdom time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output In a far away kingdom lived the Ki

CD's Coding 1100

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

集训第一次周赛题目及题解

A. Help Vasilisa the Wise 2 Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 524288/262144K (Java/Other) Total Submission(s) : 42   Accepted Submission(s) : 12 Problem Description

大神养成中..... 3541

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

CF:99A. Help Far Away Kingdom

#include #include using namespace std; int main(){ string num; while(cin>>num){ for(int i=0;i<num.length();++i){ if(num[i]=='.'){ if(num[i-1]=='9'){

Ac_freedom 787

How far away ?

There are n houses in the village and some bidirectional roads connecting them. Every day peole always like to ask like this "How far is it if I want to go from house A to house B"? Usually it hard to

---小菜鸟--- 484

Help Victoria the Wise + Friends + Hockey

【题目】2174: Help Victoria the WiseTime Limit: 2 Sec  Memory Limit: 256 MBSubmit: 16  Solved: 6[Submit][Status][Web Board]DescriptionA. Help Victoria the Wisetime limit per test1 secondmemory limit per t...

菜鸡成长史 594

7.12训练

2174: Help Victoria the Wise时间限制: 2 Sec  内存限制: 256 MB提交: 21  解决: 9[提交][状态][讨论版]题目描述time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasilisa the Wis...

积少成多,水滴石穿 274

【日常训练】Help Far Away Kingdom(Codeforces 99A)

题意与分析 题意很简单,但是注意到小数可能有一千位,作为一周java选手的我选择了java解决。 这里的分析会归纳一些必要的Java API:(待补) 代码 /* * ACM Code => cf99a.java * Written by Sam X * Date: 三月, 19, 2019 * Time: 10:08 */ import java.util.*; import j...

weixin_30607029的博客 254

Codeforces Gym 101933 K King's Colors(二项式反演)

K. King's Colors time limit per test 1.0 s memory limit per test 256 MB input standard input output standard output Far, far away, there is the mystical Kingdom of Trees (more formally, "Roy...

记录一些思考的过程。 1173

Codeforces - 99B. Help Chef Gerasim - 排序

Help Chef Gerasim 题目链接 分类:implementation sortings 1.题意概述 给你n个茶杯,里面分别有a[i]毫升的水,现在要你最多倒一次使得所有杯子里面水的容量相同。 2.解题思路 直接排序以后,最终答案就是总容量总杯子数\frac{总容量}{总杯子数},让水最多的倒给最少的即可,还有一些trick点,比如总杯子数不能整除总容量,还有需要倒多次的情

终有绿洲摇曳在沙漠 893

Codeforces 999

A /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) using namespace std; typedef long long ll; typedef unsigned long long ull; const int dir[8][2] = {{0, 1...

baichuan9723的博客 173

Codeforces 143A Help Vasilisa the Wise 2(暴力)

Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open i

HJY 521
上一篇: UVA 10341 - Solve It(二分)
下一篇: CodeForces 141B - Hopscotch
coco430
博客等级 码龄14年 9粉丝 107原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值