您的位置:首页 > 产品设计 > UI/UE

B - Bill Total Value(小数点问题处理)

2017-11-24 09:22 429 查看
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.


Example

Input

chipsy48.32televizor12.390


Output

12.438.32


Input

a1b2c3.38


Output

6.38


Input

aa0.01t0.03


Output

0.04


题意:算总和,如果这个数字小数点后面有三位的话,这三位就是整数,如果小数点后面只有两位的话,这两位是小数,不会出现一位的情况。在计算的过程中把所有小数加起来,把所有整数加起来,要及得最后在输出之前看一下小数加到需要进位的情况。字符串输入,每遇到一个数就分别把他的 整数部分和小数部分加起来。

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char s[10005];
int main()
{
int dol=0, cen=0;
scanf("%s",s);
char num[10005];
int len = strlen(s);
int i,j;
for(i=0;i<len;i++)
{
if(s[i]>='a'&&s[i]<='z')
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;
int 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[1100],ct1 = 0;
memset(re1,0,sizeof(re1));
if(dol == 0)
printf("0");
else
{
while(dol>0)
{
re1[ct1++] = dol%10;
dol /= 10;
}
}
int dian = 0;
for(int k = ct1-1;k>=0;k--)///数是倒着存的
{
dian++;
printf("%d",re1[k]);
if((ct1-dian)%3==0&&(ct1-dian)!=0)
{
printf(".");
}

}
if(cen!=0)
{
printf(".");
printf("%02d\n",cen);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐