Bill Total Value
1 second
256 megabytes
standard input
standard output
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.
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.
Print the total price exactly in the same format as prices given in the 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>
#include <unordered_map>
#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++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<ll,int>
#define Lson L, mid, ls[rt]
#define Rson mid+1, R, rs[rt]
#define sys system("pause")
const int maxn=1e5+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
inline ll read()
{
ll x=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m,k,t;
char a[maxn];
double ans,now,ca;
int main()
{
int i,j;
scanf("%s",a);
int len=strlen(a);
a[len]='a';
rep(i,,len)
{
if(a[i]>=''&&a[i]<='')
{
j=i;
now=,ca=;
int cnt=;
while((a[j]>=''&&a[j]<='')||a[j]=='.')j++;
while(a[j-]!='.'&&j->i)cnt++,j--;
if(cnt==&&j->i)
{
now+=0.1*(a[j]-'');
now+=0.01*(a[j+]-'');
for(k=i;k<j;k++)if(a[k]>=''&&a[k]<='')ca=ca*+a[k]-'';
}
else if(cnt==&&j->i)
{
for(k=i;k<j+;k++)if(a[k]>=''&&a[k]<='')ca=ca*+a[k]-'';
}
else
{
for(k=i;a[k]>=''&&a[k]<='';k++)ca=ca*+a[k]-'';
}
ca+=now;ans+=ca;
while(a[j]>=''&&a[j]<='')j++;
i=j;
}
}
sprintf(a,"%.2f",ans);
len=strlen(a);
for(i=;i<=len-;i++)
{
printf("%c",a[i]);
if(len--i>&&(len--i)%==)printf(".");
}
if(a[len-]>''||a[len-]>'')printf(".%c%c\n",a[len-],a[len-]);
//system("Pause");
return ;
}
Bill Total Value的更多相关文章
- 【21.67%】【codeforces 727B】Bill Total Value
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Codeforce727B --- Bill Total Value(字符串处理 正则表达式)
先说一下正则表达式 %*[a-z]表示忽略前面的小写字符,%[0-9]表示把紧接着非字符的连续数字存入t字符串中去; 从"abc123de4f"中得到"123" ...
- CodeForces--TechnoCup--2016.10.15--ProblemB--Bill Total Value(字符串处理)
Bill Total Value time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- angularjs入门学习【应用剖析中篇】
在上一节讲完了关于应用开发中如数据绑定,加入样式一类的基础操作后,接下来,将在应用中,与控制其有关的一些事件... 一.UI和控制器的分离 我们须要明白控制器在应用中的三个作用: [1]在应用模型中设 ...
- angularjs应用骨架(2)
时隔一个星期,接着上一篇的angularjs应用骨架继续聊聊angularjs其他的其他的内容. 区分UI和控制器的职责 在应用控制器中有三种职责: 1.为应用中模型设置初始状态 2.通过$scope ...
- AngularJs 第三节随笔
利用$scope暴露模型数据 利用向控制器传递$scope对象的机制,可以把模型数据暴露给试图.在你的应用中可能还有其他数据,但是只有通过$scope 触及这些数据,angular才会把它当成数据模型 ...
- PAT1016 × PAT1017
本次题解是综合1016和1017两道题来讲解,原因无他,因为这两道都是模拟题,综合字符串处理.排序等考点 接手一道模拟题,一定要快速且准确地了解模拟的过程,清晰题目涉及的关键信息.比如1016要计算电 ...
- ZOJ 2679 Old Bill(数学)
主题链接:problemCode=2679" target="_blank">http://acm.zju.edu.cn/onlinejudge/showProbl ...
- 【BZOJ1879】【SDOI2009】Bill的挑战 [状压DP]
Bill的挑战 Time Limit: 4 Sec Memory Limit: 64 MB[Submit][Status][Discuss] Description Input 第一行:一个整数T, ...
随机推荐
- Sass入门:第四章
1.加法 加法运算是Sass中运算的一种,在变量或属性中都可以做加法运算.如: .box { width: 20px + 8in; } 编译出来的CSS: .box { width: 788px; } ...
- 关于Android L软件安装问题的发现
android5.0可能存在的问题: 保留数据刷入导致通知栏无法下拉 按home键不能回到桌面 sdcard无法读取等等 刷了Android L之后,有一部分软件无法正常安装,多表现为 同一家公司开发 ...
- CentOS系统使用配置文件修改IP地址详细教程
在VM虚拟机安装的centos系统,默认使用的是dhcp自动获取ip地址的方式,而我自己想用这个centos在局域网内搭建一个小型演示站点,这个自动获取ip地址的方式就明显不好了,那么centos如何 ...
- table边框1px
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- OC之消息调用过程
Bird * aBird = [[Bird alloc] init]; [aBird fly]; 中对 fly 的调用,编译器通过插入一些代码,将之转换为对方法具体实现 IMP 的调用,这个 IMP ...
- genymotion模拟器配置Genymotion-ARM-Translation 兼容包
前提是你的adb的环境已经配置正确,不知道怎么配置的可参考http://jingyan.baidu.com/article/17bd8e52f514d985ab2bb800.html 如果还不成功的话 ...
- BFS详解
广度优先搜索详解 1. 也称宽度优先搜索,顾名思义,就是将一棵树一层一层往下搜.算法首先搜索和s距离为k的所有顶点,然后再去搜索和S距离为k+l的其他顶点.BFS是一种完备策略,即只 ...
- 如何成为出色的IT项目经理:成功的五个关键因素
“出色”的IT 项目经理的定义不是一成不变的.随着经济和商业因素的改变,项目经理的角色进行调整以适应新的需求,迎接新的挑战. 除了一般的困惑之外,还有一种看法就是,在组织中,不同的人对于项目经理的看法 ...
- MemoryStream 转 pdf
在项目开发中用到将MemoryStream 转pdf,在转化过程中需要建了一个.dom格式的模板,先保存为.doc文件,然后再转换为.pdf. 有一个插件感觉好不错,给大家推荐一下. dll下载链接 ...
- ELK 基本搭建
ELK是一套日志分析系统: 开发人员不能登录线上服务器查看详细日志各个系统都有日志,日志数据分散难以查找日志数据量大,查询速度慢,或者数据不够实时一个调用会设计多个系统,难以在这些系统的日志中快速定位 ...