题目链接: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. Smallest multiple

    problem 5:Smallest multiple 题意:求最小的正数,使得其可以被1-20整除 代码如下: #ifndef PRO5_H_INCLUDED #define PRO5_H_INCL ...

  2. jmeter连接数据库

    新建一个 Thread Group: 新增 JDBC Connection Configuration: 点击新增的 JDBC Connection Configuration ,需要修改的参数包括: ...

  3. 转载一篇nm命令使用的文章,虽然没用用这个方法解决但是文章很好

    http://blog.csdn.net/acs713/article/details/13505931

  4. Vs2015 Ef 连接Oracle 出现OracleInternal.Common.ConfigBaseClass 的解决办法

    如果配置没问题的话,就是 Oracle.ManagedDataAccess 在全局程序集的版本问题 解决方法方法 将Oracle.ManagedDataAccess  GAC全局程序集中移除 1:用C ...

  5. 【转】Jmeter(三)-简单的HTTP请求(非录制)

    首先建立一个线程组(Thread Group),为什么所有的请求都要加入线程组这个组件呢?不加不行吗?答案当然是不行的.因为jmeter的所有任务都必须由线程处理,所有任务都必须在线程组下面创建. 选 ...

  6. PhpMyAdmin隐藏数据库设置同前缀失效的问题

    用PhpMyAdmin默认会把所有数据库都显示出来,一些如 MySQL,information_schema之类的也会显示,这样既不安全看着也不爽,隐藏掉最好. 修改 config.inc.php 或 ...

  7. CodeForces 670A Holidays

    简单题. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #inclu ...

  8. SEO之关键词选择

    在网站优化中,关键词应该是奠基石,选择好关键词的重要性也不言而喻了.怎样选择合理化的关键词呢?这个是我今天了解到的. 1.选择的关键词首先是有人搜索过的.没人搜索的词优化就是浪费时间. 2.做有效流量 ...

  9. ajax使用json

    json是什么什么的废话不说了,去百度吧.我这里介绍一下我为何要使用json.我使用ajax响应返回值时,项目中需求要返回多个值,不能只返回一个值.这时候就想起来用到json了.这可能只是json的一 ...

  10. Scala 中的 apply 和 update 方法[转]

    原文链接:http://blog.csdn.net/lyrebing/article/details/21696581 Scala 是构建在 JVM 上的静态类型的脚本语言,而脚本语言总是会有些约定来 ...