ZOJ 2476 Total Amount

ZOJ 2476 Total Amount

Time Limit: 2 Sec  Memory Limit: 128 MB

Submit: 13  Solved: 6

[Submit][Status][Web Board]

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 <iostream>
#include<cstdio>
#include<cstring>

using namespace std;
char a[30],ch[20];
long long sum,ans;
int i,n,l;
int main()
{
    while(scanf("%d",&n) && n)
    {
       ans=0;
       for(;n>0;n--)
       {
           scanf("%s",ch);
           l=strlen(ch);
           sum=0;
           for(i=1;i<l;i++)
            if(ch[i]>=‘0‘ && ch[i]<=‘9‘)
                sum=sum*10+ch[i]-‘0‘;
           ans+=sum;
       }
       printf("%c",ch[0]);
       a[1]=char(ans%10+48);
       ans=ans/10;
       a[2]=char(ans%10+48);
       ans=ans/10;
       a[3]=‘.‘;
       l=3;
       if (ans==0) {a[4]=‘0‘; l=4;}
        else
        {
            int num=0;
            while(ans>0)
            {
               if (num==3) a[++l]=‘,‘,num=0;
               a[++l]=char(ans%10+48);
               ans=ans/10;
               num++;
            }
        }
       for(i=l;i>=1;i--) printf("%c",a[i]);
       printf("\n");
    }
    return 0;
}
时间: 2024-08-08 05:13:48

ZOJ 2476 Total Amount的相关文章

[dp] zoj 3769 Diablo III

题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3769 Diablo III Time Limit: 2 Seconds      Memory Limit: 65536 KB Diablo III is an action role-playing video game. A few days ago, Reaper of Souls (ROS), the new expansion of Diablo I

A1079. Total Sales of Supply Chain (25)

A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer. Starting from one root supplier, everyone on the chain buys products from one's supplier in a pric

pat1079. Total Sales of Supply Chain (25)

1079. Total Sales of Supply Chain (25) 时间限制 250 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to c

PAT1079. Total Sales of Supply Chain

A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer. Starting from one root supplier, everyone on the chain buys products from one's supplier in a pric

1079. Total Sales of Supply Chain (25)

时间限制 250 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer. Starting from one root supplie

ZOJ 2315 New Year Bonus Grant

New Year Bonus Grant Time Limit: 5000ms Memory Limit: 32768KB This problem will be judged on ZJU. Original ID: 231564-bit integer IO format: %lld      Java class name: Main Special Judge All programmers of Mocrosoft software company are organized in

PAT 1079. Total Sales of Supply Chain (25)

1079. Total Sales of Supply Chain (25) A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer. Starting from one root supplier, everyone on the chain buys

PAT 1079 Total Sales of Supply Chain[比较]

1079 Total Sales of Supply Chain(25 分) A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer. Starting from one root supplier, everyone on the chain buys

[Daily Coding Problem] Find the total number of solutions of a linear equation of n variables

Given a linear equation of n variables, find the total number of non-negative integer solutions of it. All coefficients are positive. Example: input: x + 2 * y = 5 output: 3,  the 3 possible integer solutions are x = 1, y = 2; x = 3, y = 1; x = 5, y