Description
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.
Sample Input
chipsy48.32televizor12.390
12.438.32
a1b2c3.38
6.38
aa0.01t0.03
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>
#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++)
const int inf_int = 2e9;
const long long inf_ll = 2e18;
#define inf_add 0x3f3f3f3f
#define mod 1000000007
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=5e2+10;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline int read(){int ra,fh;char rx;rx=getchar(),ra=0,fh=1;
while((rx<'0'||rx>'9')&&rx!='-')rx=getchar();if(rx=='-')
fh=-1,rx=getchar();while(rx>='0'&&rx<='9')ra*=10,ra+=rx-48,
rx=getchar();return ra*fh;}
//#pragma comment(linker, "/STACK:102400000,102400000")
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;}
char s[10005];
int main()
{
ll dol=0,cen=0;
cin >> s;
char num[10005];
int len = strlen(s);
int i,j;
for(i=0;i<len;i++)
{
if(s[i]<='z'&&s[i]>='a')
continue;
memset(num,0,sizeof(num));
for(j=i;j<len;j++)
{
if(s[j]<='z'&&s[j]>='a'||j>=len)
{
num[j] = '\0';
break;
}
num[j-i] = s[j];
}
i = j-1;
ll dolt=0,cent=0;
int len1 = strlen(num);
if(num[len1-3]=='.')
{
cent += (int)(num[len1-1]-'0');
cent += ((int)(num[len1-2]-'0'))*10;
cen += cent;
for(int k=0;k<len1-3;k++)
{
if(num[k]=='.')
continue;
dolt = dolt*10+(int)(num[k]-'0');
}
dol+=dolt;
}
else
{
for(int k=0;k<len1;k++)
{
if(num[k]=='.')
continue;
dolt = dolt*10+(int)(num[k]-'0');
}
dol+=dolt;
}
}
dol += cen/100;
cen %= 100;
int re1[1000],ct1=0;
memset(re1,0,sizeof(re1));
if(dol==0)
cout << "0";
else
{
while(dol!=0)
{
re1[ct1++] = dol%10;
dol/=10;
}
}
int dian=0;
for(int k=ct1-1;k>=0;k--)
{
dian++;
cout << re1[k];
if((ct1-dian)%3==0&&(ct1-dian)!=0)
{
cout << ".";
}
}
if(cen!=0)
cout << ".";
if(cen!=0)
{
if(cen<10)
{
cout << "0" << cen;
}
else
{
cout << cen/10 <<cen%10;
}
}
cout <<endl;
return 0;
}