- Total Amount

Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

Description

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<bits/stdc++.h>
using namespace std;
const int maxn=1e++;
char a[maxn];
int c[maxn],d[maxn],ans[maxn];
int main()
{
int T;
while(~scanf("%d",&T) && T)
{
memset(ans,,sizeof(ans));
memset(d,,sizeof(d));
int index,cnt=;
while(T--)
{
memset(c,,sizeof(c));
memset(a,,sizeof(a));
scanf("%s",a);
int k=;
for(int i=; i<strlen(a); i++)
{
if(isdigit(a[strlen(a)-i-]))
c[k++]=a[strlen(a)-i-]-'';
}
for(int i=; i<; i++)
{
d[i]+=c[i];
d[i+]+=d[i]/;
d[i]%=;
}
}
for(int i=; i>=; i--)
{
if(d[i]!=)
{
index=i;
break;
}
}
for(int i=index; i>=; i--)
ans[cnt++]=d[i];
printf("$");
if(cnt==)printf("");
else
{
for(int i=; i<cnt; i++)
{
printf("%d",ans[i]);
if((cnt-i-)%== && i!=cnt-)
printf(",");
}
}
printf(".%d%d\n",d[],d[]);
}
return ;
}

ZOJ 2476 Total Amount 字符串模拟的更多相关文章

  1. ZOJ 2476 Total Amount 字符串

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

  2. ZOJ 2476 Total Amount

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2476 Time Limit: 2 Seconds         ...

  3. Codeforces Round #425 (Div. 2) B. Petya and Exam(字符串模拟 水)

    题目链接:http://codeforces.com/contest/832/problem/B B. Petya and Exam time limit per test 2 seconds mem ...

  4. 用字符串模拟两个大数相加——java实现

    问题: 大数相加不能直接使用基本的int类型,因为int可以表示的整数有限,不能满足大数的要求.可以使用字符串来表示大数,模拟大数相加的过程. 思路: 1.反转两个字符串,便于从低位到高位相加和最高位 ...

  5. HDU-3787(字符串模拟)

    Problem Description 给定两个整数A和B,其表示形式是:从个位开始,每三位数用逗号","隔开.现在请计算A+B的结果,并以正常形式输出.   Input 输入包含 ...

  6. HDU-1002.大数相加(字符串模拟)

    本题大意:给出两个1000位以内的大数a 和b,让你计算a + b的值. 本题思路:字符串模拟就能过,会Java的大佬应该不会点进来...... 参考代码: #include <cstdio&g ...

  7. HDU-Digital Roots(思维+大数字符串模拟)

    The digital root of a positive integer is found by summing the digits of the integer. If the resulti ...

  8. Vigenère密码 2012年NOIP全国联赛提高组(字符串模拟)

    P1079 Vigenère 密码 题目描述 16 世纪法国外交家 Blaise de Vigenère 设计了一种多表密码加密算法――Vigenère 密 码.Vigenère 密码的加密解密算法简 ...

  9. CCF(JSON查询:40分):字符串+模拟

    JSON查询 201709-3 纯字符串模拟,考的就是耐心和细心.可惜这两样我都缺... #include<iostream> #include<cstdio> #includ ...

随机推荐

  1. webpack2引入bootstrap的坑

    在webpack官网教程的代码分离-css章节中,给出的例子是这样的. //安装 ExtractTextWebpackPlugin 如下 npm install --save-dev extract- ...

  2. 计算mysql中某个字段某字符出现的次数,case when 和 截取字符的用法

    select LENGTH(type) - LENGTH(replace(type,'_','')) as counts from sa_log_olap where type like 'XX_XX ...

  3. DOM增删操作(select动态增加和删除以及清空)

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...

  4. redis中文

    Redis 是完全开源免费的,遵守BSD协议,先进的key - value持久化产品.它通常被称为数据结构服务器,因为值(value)可以是         字符串(String),         ...

  5. Vue 框架-05-动态绑定 css 样式

    Vue 框架-05-动态绑定 css 样式 今天的小实例是关于 Vue 框架动态绑定 css 样式,这也是非常常用的一个部分 首先说一下 动态绑定,相对的大家都知道静态绑定,静态绑定的话,直接加 cl ...

  6. Java XML SAX 解析注意

    版权声明: 欢迎转载,但请保留文章原始出处 作者:GavinCT 出处:http://www.cnblogs.com/ct2011/p/4002738.html 什么时候可以把解析值赋给对象 一般从网 ...

  7. 回归JavaScript基础(六)

    主题:引用类型Date.RegExp的介绍. 上节主要主要介绍了Object.Array引用类型.这节将继续为大家介绍引用类型,并对书中的一些知识点进行总结与归纳,也借此巩固自己对JavaScript ...

  8. Object、T(以下代指泛型)、?的区别

    因为最近看了很多项目底层都使用了T,?泛型,于是百度了一下有如下理解 我们先来试着理解一下Object类,学习Java的应该都知道Object是所有类的父类,注意:那么这就意味着它的范围非常广!首先记 ...

  9. ALTER 语句总结

    一.基础语句 ALTER TABLE 语句 ALTER TABLE 语句用于在现有表中添加.删除或修改列. <!--若要向表中添加列,请使用以下语法:--> ALTER TABLE tab ...

  10. 3.HTML颜色

    一,HTML 颜色采用的是 RGB 颜色,是通过对红(R).绿(G).蓝(B)三个颜色通道的变化以及它们相互之间的叠加来得到各式各样的颜色的,RGB即是代表红.绿.蓝三个通道的颜色. <p st ...