Technocup 2017 - Elimination Round 1 (Unofficially Open for Everyone, Rated for Div. 2) B

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 1and 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

题意:给出价格,不过价格表示不太一样,如果是小数点后面是3个数字,只是数字分割符号,比如12,345 表示12345,当然是两个以下说明是小数点,求所有的价格总和,并按照题意表示方式输出解法:1 主要在于如何把数字转化成常规数字。我用a表示整数,b表示小数2 前面的数字自然是整数,中间出现的数字判断是不是长度为3,后面的数字也同样判断一下,然后放入a和b内3 再判断b是不是有进位4 按照题目意思输出,大概就是小数是1~2位。整数位是3位,判断一下5 代码好长。。其实重复部分很多
#include<bits/stdc++.h>
using namespace std;
long long a,b;
int main(){
    string s;
    cin>>s;
    int len=s.length();
    int i=0;
    while(i<len){
        if(s[i]>=‘a‘&&s[i]<=‘z‘){
            i++;
        }
        if(s[i]>=‘0‘&&s[i]<=‘9‘){
            int f=0;
            long long ans=0;
            long long pos=0;
            long long num=0;
            while(s[i]>=‘0‘&&s[i]<=‘9‘){
                pos*=10;
                pos+=(s[i]-‘0‘);
                i++;
            }
            if(s[i]==‘.‘){
                f++;
                i++;
                int x=1;
                while(s[i]>=‘0‘&&s[i]<=‘9‘){
                    ans*=10;
                    ans+=(s[i]-‘0‘);
                    i++;
                    x*=10;
                }
                if(x>=1000){
                    pos*=x;
                    pos+=(ans);
                }else{
                    b+=ans;
                   // cout<<b<<"A"<<endl;
                   // cout<<"A"<<endl;
                }
            }
            if(s[i]==‘.‘&&f==1){
                i++;
                long long x=1;
                while(s[i]>=‘0‘&&s[i]<=‘9‘){
                    num*=10;
                    num+=(s[i]-‘0‘);
                    i++;
                    x*=10;
                }
                if(x>=1000){
                    pos*=x;
                    pos+=num;
                }else{
                   b+=num;
                }
            }else{
                i++;
            }
           // cout<<pos<<" "<<b<<endl;
            a+=pos;
        }
    }

    a+=(b/100);
    b%=100;
    //cout<<a<<" "<<b<<endl;
    string ss="";
    if(a==0&&b==0){
        cout<<"0.0"<<endl;
        return 0;
    }
    if(a==0&&b){
        if(b<10){
            cout<<"0.0"<<b<<endl;
        }else{
            string ls="";
            while(b){
                long long dns=b%10;
                ls+=(dns+‘0‘);
                b/=10;
            }
            reverse(ls.begin(),ls.end());
            cout<<"0."<<ls<<endl;
        }
        return 0;
    }
    if(a&&b==0){
        int los=0;
        while(a){
            long long dns=a%10;
            if(los%3==0&&los){
                ss+=‘.‘;
            }
            ss+=(dns+‘0‘);
            a/=10;
            los++;
        }
        int ll=ss.length();
        reverse(ss.begin(),ss.end());
        cout<<ss<<endl;
    }else{
        int los=0;
        while(a){
            long long dns=a%10;
            if(los%3==0&&los){
                ss+=‘.‘;
            }
            ss+=(dns+‘0‘);
            a/=10;
            los++;
        }
        int ll=ss.length();
        reverse(ss.begin(),ss.end());
        if(b<10){
            cout<<ss<<".0"<<b<<endl;
        }else{
            string ls="";
                while(b){
                    long long dns=b%10;
                    ls+=(dns+‘0‘);
                    b/=10;
                }
            reverse(ls.begin(),ls.end());
            cout<<ss<<"."<<ls<<endl;
        }
    }
    return 0;
}
				
时间: 2024-11-05 17:16:57

Technocup 2017 - Elimination Round 1 (Unofficially Open for Everyone, Rated for Div. 2) B的相关文章

Technocup 2017 - Elimination Round 1 (Unofficially Open for Everyone, Rated for Div. 2) A

Vasily has a number a, which he wants to turn into a number b. For this purpose, he can do two types of operations: multiply the current number by 2 (that is, replace the number x by 2·x); append the digit 1 to the right of current number (that is, r

Technocup 2017 - Elimination Round 1 (Unofficially Open for Everyone, Rated for Div. 2) C

This is an interactive problem. You should use flush operation after each printed line. For example, in C++ you should usefflush(stdout), in Java you should use System.out.flush(), and in Pascal - flush(output). In this problem you should guess an ar

codeforces Technocup 2017 - Elimination Round 2/Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2) 题解

久违的下午场,打了一场状态不错一下rank12涨了207~~~ A. Interview with Oleg 题意: 给你一个长度不超过100的串,把其中ago开头后面不接或者接gogogo...的部分全部变成*** 思路: 水水,扫 /* *********************************************** Author :devil ************************************************ */ #include <cstdi

codeforces Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)// 二分的题目硬生生想出来ON的算法

A. Road to Cinema 很明显满足二分性质的题目. 题意:某人在起点处,到终点的距离为s. 汽车租赁公司提供n中车型,每种车型有属性ci(租车费用),vi(油箱容量). 车子有两种前进方式 :①. 慢速:1km消耗1L汽油,花费2分钟. ②.快速:1km消耗2L汽油,花费1分钟. 路上有k个加油站,加油不需要花费时间,且直接给油箱加满. 问在t分钟内到达终点的最小花费是多少?(租车子的费用)  若无法到达终点,输出-1 不谈二分的写法.. 我们考虑离散化可修改的点  和限制的点位置

【模拟】 Codeforces Round #434 (Div. 1, based on Technocup 2018 Elimination Round 1) C. Tests Renumeration

题意:有一堆数据,某些是样例数据(假设X个),某些是大数据(假设Y个),但这些数据文件的命名非常混乱.要你给它们一个一个地重命名,保证任意时刻没有重名文件的前提之下,使得样例数据命名为1~X,大数据命名为X+1~X+Y. 先把未使用的名字压进两个栈. 分为三轮:第一轮把占用了对方名字的样例数据以及占用了对方名字的大数据放进两个队列,然后不断反复尝试对这两个队列进行出队操作,每次将占用对方名字的改成一个未被使用的正确名字(从栈里取出),然后将占用的名字压进另一个栈.由于每个数据只会出队一次,所以是

Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) C. Vasya and Golden Ticket

C. Vasya and Golden Ticket time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Recently Vasya found a golden ticket - a sequence which consists of nn digits a1a2-ana1a2-an. Vasya considers a ti

Technocup 2019 - Elimination Round 2

http://codeforces.com/contest/1031 (如果感觉一道题对于自己是有难度的,不要后退,懂0%的时候敲一遍,边敲边想,懂30%的时候敲一遍,边敲边想,懂60%的时候敲一遍,边敲边想,(真实情况是你其实根本不用敲那么多遍--),然后,这道题你就差不多可以拿下了ψ(`?′)ψ) (IO模板在最后的蛋里) A. Golden Plate n*m矩形,最外圈为第一圈,间隔着选k个圈,问总共占多少给格子 每圈贡献=2n'+2m'-4,圈圈长宽以-4递减下去 public sta

[Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3)][C. Playing Piano]

http://codeforces.com/contest/1079/problem/C 题目大意:给出一个数列a[n],让构造一个满足下列条件的数列b[n]:如果a[i]>a[i-1]那么b[i]>b[i-1],如果a[i]<a[i-1]那么b[i]<b[i-1],如果a[i]==a[i-1],那么b[i]!=b[i-1].其中1<=b[i]<=5  1<=a[i]<=2*1e5. 题解:dp[i][j]表示在位置i处取j时是否成立,如果成立则dp[i][

Codeforces Round #591 (Div. 2, based on Technocup 2020 Elimination Round 1) 题解

A..B略 C 对当前的值排序,再二分答案,然后对于(i%x==0 && i%y==0)放入大的,再放其他的贪心解决即可. #include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> #include<map> #define LL long long #define lson rt<<1 #define rson rt<