Bill Total Value

Bill Total Value
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasily exited from a store and now he wants to recheck the total price of all purchases in his bill. The bill is a string in which the names of the purchases and their prices are printed in a row without any spaces. Check has the format "name1price1name2price2...namenpricen", where namei (name of the i-th purchase) is a non-empty string of length not more than 10, consisting of lowercase English letters, and pricei (the price of the i-th purchase) is a non-empty string, consisting of digits and dots (decimal points). It is possible that purchases with equal names have different prices.

The price of each purchase is written in the following format. If the price is an integer number of dollars then cents are not written.

Otherwise, after the number of dollars a dot (decimal point) is written followed by cents in a two-digit format (if number of cents is between 1 and 9 inclusively, there is a leading zero).

Also, every three digits (from less significant to the most) in dollars are separated by dot (decimal point). No extra leading zeroes are allowed. The price always starts with a digit and ends with a digit.

For example:

  • "234", "1.544", "149.431.10", "0.99" and "123.05" are valid prices,
  • ".333", "3.33.11", "12.00", ".33", "0.1234" and "1.2" are not valid.

Write a program that will find the total price of all purchases in the given bill.

Input

The only line of the input contains a non-empty string s with length not greater than 1000 — the content of the bill.

It is guaranteed that the bill meets the format described above. It is guaranteed that each price in the bill is not less than one cent and not greater than 106 dollars.

Output

Print the total price exactly in the same format as prices given in the input.

Examples
input
chipsy48.32televizor12.390
output
12.438.32
input
a1b2c3.38
output
6.38
input
aa0.01t0.03
output
0.04
分析:字符串模拟;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <unordered_map>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<ll,int>
#define Lson L, mid, ls[rt]
#define Rson mid+1, R, rs[rt]
#define sys system("pause")
const int maxn=1e5+10;
using namespace std;
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
inline ll read()
{
    ll x=0;int f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,m,k,t;
char a[maxn];
double ans,now,ca;
int main()
{
    int i,j;
    scanf("%s",a);
    int len=strlen(a);
    a[len]='a';
    rep(i,0,len)
    {
        if(a[i]>='0'&&a[i]<='9')
        {
            j=i;
            now=0,ca=0;
            int cnt=0;
            while((a[j]>='0'&&a[j]<='9')||a[j]=='.')j++;
            while(a[j-1]!='.'&&j-1>i)cnt++,j--;
            if(cnt==2&&j-1>i)
            {
                now+=0.1*(a[j]-'0');
                now+=0.01*(a[j+1]-'0');
                for(k=i;k<j;k++)if(a[k]>='0'&&a[k]<='9')ca=ca*10+a[k]-'0';
            }
            else if(cnt==3&&j-1>i)
            {
                for(k=i;k<j+3;k++)if(a[k]>='0'&&a[k]<='9')ca=ca*10+a[k]-'0';
            }
            else
            {
                for(k=i;a[k]>='0'&&a[k]<='9';k++)ca=ca*10+a[k]-'0';
            }
            ca+=now;ans+=ca;
            while(a[j]>='0'&&a[j]<='9')j++;
            i=j;
        }
    }
    sprintf(a,"%.2f",ans);
    len=strlen(a);
    for(i=0;i<=len-4;i++)
    {
        printf("%c",a[i]);
        if(len-4-i>0&&(len-4-i)%3==0)printf(".");
    }
    if(a[len-1]>'0'||a[len-2]>'0')printf(".%c%c\n",a[len-2],a[len-1]);
    //system("Pause");
    return 0;
}

转载于:https://www.cnblogs.com/dyzll/p/5965685.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值