题目链接: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. C# 线程同步之排它锁/Monitor监视器类

    一.Monitor类说明,提供同步访问对象的机制. 1.位于System.Threading命名空间下,mscorlib.dll程序集中. 2.Monitor通过获取和释放排它锁的方式实现多线程的同步 ...

  2. make -j 多核并行编译 导致笔记本过热 自动关机保护

    中午在装着CentOS的笔记本上把 Oneinstack 跑起来然后去上班了,本来等着下班回来用的,回来之后发现是关机状态,环境也没有装好. 查看日志,找不到相关信息,甚至还以为是被入侵了.又试了几遍 ...

  3. swift3.0 运行时获取类的属性

    //定义Person类 class Person: NSObject { var name: String? //注意这里基本数据类型我定义的是必选属性 var age: Int = override ...

  4. PRML 第一章mindmap

    PRML读了很长时间了,但是一直没有完全搞明白,很多概念都是不太清楚,于是从第一章开始重读.读的过程中会将这个内容结构用mindmap的形式记录下来,一是通过这种方式帮助自己理清楚思路,二是在之后可以 ...

  5. Beego学习笔记——开始

    beego简介 beego是一个快速开发Go应用的http框架,他可以用来快速开发API.Web.后端服务等各种应用,是一个RESTFul的框架,主要设计灵感来源于tornado.sinatra.fl ...

  6. SeleniumServer3.0

    package base.test.demo; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import ...

  7. IOS 加载网络图片2

    //1. NSData dataWithContentsOfURL // [self.icon setImage:[UIImage imageWithData:[NSData dataWithCont ...

  8. teyi

    $arr=array('haha'=>"苹果");print_r($arr['haha']); $arr=array(0=>"苹果");$arr=a ...

  9. JDBC:四步完成MySQL数据库的连接

    ->首先,将MySQL的jar包引入 ->然后创建一个.properties的文件(例:connection.properties),在该文件中写入如下代码: jdbc.driver.cl ...

  10. Recursive - leetcode [递归]

    经验tips: Recursion is the best friend of tree-related problems. 一是只要遇到字符串的子序列或配准问题首先考虑动态规划DP,二是只要遇到需要 ...