题目链接: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的更多相关文章

  1. ZOJ 2476 Total Amount 字符串模拟

    - Total Amount Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit ...

  2. ZOJ 2476 Total Amount 字符串

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1476 题目大意: 给你n串数字组成的字符串,要求输出他们相加的和. 如:n=  ...

  3. zoj 2860 四边形优化dp

    Breaking Strings Time Limit: 2 Seconds        Memory Limit: 65536 KB A certain string-processing lan ...

  4. 1079. Total Sales of Supply Chain (25)

    时间限制 250 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A supply chain is a network of r ...

  5. 1079. Total Sales of Supply Chain (25) -记录层的BFS改进

    题目如下: A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyon ...

  6. PAT1079 :Total Sales of Supply Chain

    1079. Total Sales of Supply Chain (25) 时间限制 250 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...

  7. 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 ...

  8. A1079. Total Sales of Supply Chain

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

  9. PAT 甲级 1079 Total Sales of Supply Chain

    https://pintia.cn/problem-sets/994805342720868352/problems/994805388447170560 A supply chain is a ne ...

随机推荐

  1. Struts1和Struts2的区别和对比

    Struts1和Struts2的区别和对比: Action 类: • Struts1要求Action类继承一个抽象基类.Struts1的一个普遍问题是使用抽象类编程而不是接口. • Struts 2  ...

  2. springmvc中返回页面,只在iframe中跳转,而不是整个页面,解决方法。

    问题描述:在我写的主页面中用到了iframe,其中在iframe中有一个button点击提交,然后在Controller中返回页面的时候,是在iframe中打开的,而不是整个页面. 最开始我想用aja ...

  3. 第一百二十六节,JavaScript,XPath操作xml节点

    第一百二十六节,JavaScript,XPath操作xml节点 学习要点: 1.IE中的XPath 2.W3C中的XPath 3.XPath跨浏览器兼容 XPath是一种节点查找手段,对比之前使用标准 ...

  4. input失效后,怎么改变它默认就有的灰色

    ☆☆☆☆☆ input:disabled { -webkit-text-fill-color: rgba(0, 0, 0, 1); -webkit-opacity: 1; } 去掉button/sel ...

  5. html5 拖拽文件到页面实现上传

    思路:监听拖拽区域的 drop 事件,阻止浏览器上的默认拖拽事件 参考:http://www.helloweba.com/view-blog-192.html 例子: <!DOCTYPE htm ...

  6. Android 简单的图片缩放方法

    很简单的一个图片缩放方法,注意要比例设置正确否则可能会内存溢出 相关问题 java.lang.IllegalArgumentException: bitmap size exceeds 32bits ...

  7. iOS项目导航栏返回按钮

    最近iOS项目中要求导航栏的返回按钮只保留那个箭头,去掉后边的文字,在网上查了一些资料,最简单且没有副作用的方法就是 [[UIBarButtonItem appearance] setBackButt ...

  8. 🐒-mysql(1)

    Mac 终端启动mysql 本文下载的mysql版本为:5.7.17.MySQL Workbench版本为:5.2.47(后面会提及如何选择下载版本) 一.下载MySQL 1.1.访问http://w ...

  9. ecshop 后台添加新的设置

    1.ecs_shop_config 表添加新的值. 2.language/zh_cn/admin/shop_config.php 设置字段后台字段名和提示信息($_LANG['cfg_name'][' ...

  10. 解决gstreamer无法播放的bug

    0 ls 1 ./start.sh 2 ps 3 kill 366 4 cd /usr/app/services/ 5 ./start.sh 6 cd ../ 7 ls 8 cd res/ 9 ls ...