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 ...
随机推荐
- 自动布局autolayout和sizeclass的使用
一.关于自动布局(Autolayout) 在Xcode中,自动布局看似是一个很复杂的系统,在真正使用它之前,我也是这么认为的,不过事实并非如此. 我们知道,一款iOS应用,其主要UI组件是由一个个相对 ...
- C# 利用ajax实现局部刷新
C#所有runat="server"的控件都会造成整个界面的刷新,如果想实现局部刷新,可以利用ajax. 需要加入的控件有ScriptManager和UpdatePanel,可以实 ...
- Windows 服务 Error 14001
如果碰到 windows 服务安装不了或者启动不了,报14001的配置文件错误,那么 可以从.exe.config入手,我这次遇到的是配置中有中文注释导致的. 我把空行以及中文的注释去掉以后,整个世界 ...
- Webupload + MVC 之上传下载
最近工作中用到了 MVC 的上传及下载 , 写下感受 本项目中用到的是百度的webuploader <!--引入Jquery--> <script src="~/Conte ...
- FTP上传下载工具(FlashFXP) v5.5.0 中文版
软件名称: FTP上传下载工具(FlashFXP) 软件语言: 简体中文 授权方式: 免费试用 运行环境: Win 32位/64位 软件大小: 7.4MB 图片预览: 软件简介: FlashFXP 是 ...
- Ansible Filter
没啥好说的. 自己看吧 http://docs.ansible.com/ansible/playbooks_filters.html
- AsyncHttpClient 中的重定向和 setEnableRedirects 方法异常解决
今天使用 AsyncHttpClient 开源库,遇到个很崩溃的问题: 方法 setEnableRedirects(false); 从名称上看应该是重定向开关的方法,设置为 false 后则普通请 ...
- android自定义控件,其三个父类构造方法有什么区别
android自定义控件时,通常需要重写父类构造函数.这三个够找函数具体啥时调用? public View (Context context) 是在java代码创建视图的时候被调用,如果是从xml填充 ...
- 使用jquery.validate.js插件进行表单里控件的验证
jsp中具体实现的代码: <%@ page language="java" contentType="text/html; charset=UTF-8" ...
- sublime插件(配合nodejs环境)
一.首先先安装nodejs,从nodejs官网下载 www.nodejs.cn 下载完成后直接安装,选择npm package版本的进行安装,安装完成后无需配置环境变量,nodejs会自动进行配置. ...