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, ...
随机推荐
- 关于cocos2dx的C++调用创建项目
我使用的是cocos2dx-2.1.4版本+cygwin,其实主要是为了配合公司项目,所以用了低版本的cocos2dx 假设已经配置环境成功: 按照对应的要求输入包名,项目名,以及TargetId,就 ...
- Delphi用ADOquery主从表例子(转总结)
http://blog.csdn.net/kandy_zheng/article/details/1639184 在sql server 的northwide 中建立主表 create table s ...
- linux上安装mono发布.net网站步骤
在linux上部署mono 1.自己安装好linux 2.使用桥接方式,让虚拟机和本机在一个局域网内 3.安装apache服务器 4.安装libgdiplug 5.安装mono 6.安装xsp 7.安 ...
- 工具类 Util.Browser
/** * @description get the param form browser * @author xf.radish * @param {String} key the param yo ...
- 安装mcrouter
下载准备: mcrouter 下载地址 : https://github.com/facebook/mcrouter gflags 下载地址:http://download.csdn.net/deta ...
- li浮动时ul高度为0,解决ul自适应高度的几种方法
网址:http://www.gxchina.com/edu/11208.html 1.给ul元素设置高度height最直接的办法是给ul元素设置一个高度,即ul标签添加height属性,代码如下: u ...
- 运行指定路径下的exe
public void StartProcess(string name) { string exeFileName = "DataControl.exe"; string sta ...
- buffer小解
Buffer代表一个缓冲区,存储二进制数据,是字节流 创建: 创建Buffer有4种方式: 1.new Buffer(size) 以字节为单位创建指定大小的Buffer eg: var buf= ne ...
- 《Think in UML》读后感
- dedecms 自定义标签的方法
function lib_demotest(&$ctag,&$refObj) { global $dsql,$envs; //属性处理 $attlist="row|12,ti ...