首页 技术 正文
技术 2022年11月14日
0 收藏 634 点赞 2,328 浏览 3081 个字

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.

Examplesinput

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=;
while(i<len){
if(s[i]>='a'&&s[i]<='z'){
i++;
}
if(s[i]>=''&&s[i]<=''){
int f=;
long long ans=;
long long pos=;
long long num=;
while(s[i]>=''&&s[i]<=''){
pos*=;
pos+=(s[i]-'');
i++;
}
if(s[i]=='.'){
f++;
i++;
int x=;
while(s[i]>=''&&s[i]<=''){
ans*=;
ans+=(s[i]-'');
i++;
x*=;
}
if(x>=){
pos*=x;
pos+=(ans);
}else{
b+=ans;
// cout<<b<<"A"<<endl;
// cout<<"A"<<endl;
}
}
if(s[i]=='.'&&f==){
i++;
long long x=;
while(s[i]>=''&&s[i]<=''){
num*=;
num+=(s[i]-'');
i++;
x*=;
}
if(x>=){
pos*=x;
pos+=num;
}else{
b+=num;
}
}else{
i++;
}
// cout<<pos<<" "<<b<<endl;
a+=pos;
}
} a+=(b/);
b%=;
//cout<<a<<" "<<b<<endl;
string ss="";
if(a==&&b==){
cout<<"0.0"<<endl;
return ;
}
if(a==&&b){
if(b<){
cout<<"0.0"<<b<<endl;
}else{
string ls="";
while(b){
long long dns=b%;
ls+=(dns+'');
b/=;
}
reverse(ls.begin(),ls.end());
cout<<"0."<<ls<<endl;
}
return ;
}
if(a&&b==){
int los=;
while(a){
long long dns=a%;
if(los%==&&los){
ss+='.';
}
ss+=(dns+'');
a/=;
los++;
}
int ll=ss.length();
reverse(ss.begin(),ss.end());
cout<<ss<<endl;
}else{
int los=;
while(a){
long long dns=a%;
if(los%==&&los){
ss+='.';
}
ss+=(dns+'');
a/=;
los++;
}
int ll=ss.length();
reverse(ss.begin(),ss.end());
if(b<){
cout<<ss<<".0"<<b<<endl;
}else{
string ls="";
while(b){
long long dns=b%;
ls+=(dns+'');
b/=;
}
reverse(ls.begin(),ls.end());
cout<<ss<<"."<<ls<<endl;
}
}
return ;
}

    					
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,029
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,519
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,367
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,146
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,781
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,859