ZOJ 2476 Total Amount
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2476
Time Limit: 2 Seconds Memory Limit: 65536 KB
Given a list of monetary amounts in a standard format, please calculate the total amount.
We define the format as follows:
1. The amount starts with '$'.
2. The amount could have a leading '0' if and only if it is less then 1.
3. The amount ends with a decimal point and exactly 2 following digits.
4. The digits to the left of the decimal point are separated into groups of three by commas (a group of one or two digits may appear on the left).
Input
The input consists of multiple tests. The first line of each test contains an integer N (1 <= N <= 10000) which indicates the number of amounts. The next N lines contain N amounts. All amounts and the total amount are between $0.00 and $20,000,000.00, inclusive. N=0 denotes the end of input.
Output
For each input test, output the total amount.
Sample Input
2
$1,234,567.89
$9,876,543.21
3
$0.01
$0.10
$1.00
0
Sample Output
$11,111,111.10
$1.11
#include<stdio.h>
#include<cstring>.
#include<iostream>
using namespace std;
long long f(int n)
{
long long res=;
while(n--)
res*=;
return res;
}
char ans[];
void change(long long a)
{
int i,j;
if(a==)
{
cout<<"";
return;
}
for(i=,j=;i<;i++,j++)
{
if(a<)break;
ans[i]=''+(a%);
a/=;
if(j%==)
{
i++;
ans[i]=',';
}
}
int len=i;
for(i=len-;i>=;i--)
{
if(i==len-&&ans[i]==',');
else cout<<ans[i];
}
}
int main()
{
int n,len,i,j;
long long resz;
int resf;
char s[];
while(cin>>n&&n)
{
resz=;
resf=;
while(n--)
{
cin>>s;
len=strlen(s);
resf+=s[len-]-'';
resf+=(s[len-]-'')*;
while(resf>=)
{
resz+=;
resf-=;
}
for(i=len-,j=;i>=;i--)
{
if(s[i]>=''&&s[i]<='')
{
resz+=(s[i]-'')*f(j);
j++;
}
}
}
cout<<"$";
change(resz);
cout<<".";
if(resf<)cout<<""<<resf<<endl;
else cout<<resf<<endl;
}
return ;
}
ZOJ 2476 Total Amount的更多相关文章
- ZOJ 2476 Total Amount 字符串模拟
- Total Amount Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Submit ...
- ZOJ 2476 Total Amount 字符串
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1476 题目大意: 给你n串数字组成的字符串,要求输出他们相加的和. 如:n= ...
- zoj 2860 四边形优化dp
Breaking Strings Time Limit: 2 Seconds Memory Limit: 65536 KB A certain string-processing lan ...
- 1079. Total Sales of Supply Chain (25)
时间限制 250 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A supply chain is a network of r ...
- 1079. Total Sales of Supply Chain (25) -记录层的BFS改进
题目如下: A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyon ...
- PAT1079 :Total Sales of Supply Chain
1079. Total Sales of Supply Chain (25) 时间限制 250 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...
- ZOJ 3769-Diablo III(DP)
描述 Diablo III is an action role-playing video game. A few days ago, Reaper of Souls (ROS), the new e ...
- A1079. Total Sales of Supply Chain
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...
- PAT 甲级 1079 Total Sales of Supply Chain
https://pintia.cn/problem-sets/994805342720868352/problems/994805388447170560 A supply chain is a ne ...
随机推荐
- angular 格式化日期
参考:http://blog.csdn.net/zk437092645/article/details/37882191 html: <input type="text" d ...
- 端口(port)的安全模式(security mode)
1. Cisco29系列交换机可以做基于2层的端口安全 ,即mac地址与端口进行绑定.2. Cisco3550以上交换机均可做基于2层和3层的端口安全, 即mac地址与端口绑定以及mac地址与ip地址 ...
- LED的串联电阻值的计算
与LED串联的电阻被用于控制该LED导通时的电流量.为了计算电阻值,你需要知道输入电源电压(Vs,一般为5V),LED的正向电压(Vf)和你需要流过LED的电源(/)的数值. 其电阻欧姆值的计算公式( ...
- Oracle odi 数据表导出到文件
最近新客户要求,以EXCEL数据方式,将数据表的内容,通过AS2协议传输到客户那边,本来打算使用存储过程直接输出EXCEL,但一想,ODI这么强大的工具应该可以直接进行转换,所以参考了一下官方标准文档 ...
- wpf 寻找某个控件下的子控件
/// <summary> /// 寻找某个控件下的子控件 /// </summary> /// <typeparam name="ChildType" ...
- Rosenbrock function
w测试最优化算法性能可通过其. https://en.wikipedia.org/wiki/Rosenbrock_function https://zh.wikipedia.org/wiki/Rose ...
- Makfile文件编写
一.make是什么 GNU make是一个工程管理器,专门负责管理.维护较多文件的处理,实现自动化编译.如果一个工程项目中,有成百上千个代码源文件,若其中一个或多个文件进过修改,make就需要能够自动 ...
- Func,Action 的介绍
Func,Action 的介绍 Func是一种委托,这是在3.5里面新增的,2.0里面我们使用委托是用Delegate,Func位于System.Core命名空间下,使用委托可以提升效率,例如在反射中 ...
- webAPI---发布(IIS)--发布遇到问题(500.19,500.21,404.8,404.3)
WebAPI的内容部分直接转自官方文档,英语水平有限,不做翻译, 发布网站在本文的后半部分 HTTP is not just for serving up web pages. It is also ...
- 删除和创建ms sql的分区文件
今天测试ms sql 的表分区的时候,不小心搞错了分区的条件.然后我想重新做一次,操作流程如下(按顺序) 1:删除SCHEME DROP PARTITION SCHEME TestSPScheme ...