Codeforces 727B Bill Total Value(附带ac代码)

作为一个博客萌新,这是我第一次在写博客,有什么没注意的地方希望各位看官大佬见谅。。

727B Bill Total Value 


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 106dollars.

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

非常非常的麻烦的一道题目,我的代码分成两部分,第一部分建立数组储存输入的字符串之中出现的所有数字,并转化成double类型求和成sum;第二部分根据题目的要求把我们求得和转换成题目里要求的奇怪格式。而这里就需要开始分类讨论了,从sum是否是整数?是否是有小数点?是否是0?我将其分为了

if(sam==0)....else if(sam%100!=0){if(sam>=100) .....else  if(sam>=10)....else...}else{if(sam>=100000)...else ...}

这么写应该不会太乱吧。。。

#include 
#include 
#include 
using namespace std;

void dx(char *z)
{
    char *ps,*pz,temp;
    ps=z;
    pz=z;
    while(*ps!='\0')ps++;
    ps--;
    while(pz='0'&&a[i]<='9')||((a[i]=='.')&&a[i+3]>='a'&&a[i+3]<='z')||((a[i]=='.')&&(a[i+3]=='\0')))
                {ss[t++]=a[i];if((a[i+1]>='a'&&a[i+1]<='z')||a[i+1]=='\0')ss[t++]=' ';}
        x=(double)(ss[0]-'0');


        for(int j=1;j=100)
            {
                for(q=0;sam/10!=0;)
                {
                    if((q==2||m==3)){ch[q++]='.';m=0;continue;}
                    ch[q]=(sam%10+'0');
                    q++;
                    sam=sam/10;
                    if(q>2)m++;
                }
                if(m==3||q==2){ch[q++]='.';ch[q]=(sam%10+'0');}
                else ch[q]=(sam%10+'0');
                dx(ch);
                printf("%s\n",ch);
            }
            else  if(sam>=10)printf("0.%lld\n",sam%100);
            else  printf("0.0%lld\n",sam%100);

        }
        else
        {
            if(sam>=100000)
            {
                sam=sam/100;
                for(q=0;sam/10!=0;)
                {
                    if(m==3){ch[q++]='.';m=0;continue;}
                    ch[q]=(sam%10+'0');
                    q++;
                    sam=sam/10;
                    m++;
                }
                if(m==3){ch[q++]='.';ch[q]=(sam%10+'0');}
                else ch[q]=(sam%10+'0');
                dx(ch);
                printf("%s\n",ch);
            }
            else printf("%lld\n",sam/100);


        }




        memset(a,0,sizeof(a));
        memset(ss,0,sizeof(ss));
        memset(ch,0,sizeof(ch));
    }

    return 0;
}

             

你可能感兴趣的:(Codeforces 727B Bill Total Value(附带ac代码))