CodeForces--TechnoCup--2016.10.15--ProblemB--Bill Total Value(字符串处理)
Bill Total Value
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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.
InputThe 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.
OutputPrint the total price exactly in the same format as prices given in the input.
Examples
Inputchipsy48.32televizor12.390Output12.438.32Inputa1b2c3.38Output6.38Inputaa0.01t0.03
Output0.04
这个题的难点在于字符串的处理,在翻看公开的代码时,我看到了一个写的特别棒的代码,充分运用了各种字符串有关的函数,感觉受益匪浅
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; } int main() {
string s;
while(cin >> s) { for(char &c : s) if(isalpha(c)) c = ' '; stringstream ss(s);
string w;
ll sum = ;
while(ss >> w) {
if(!(w.size() >= && w[w.size() - ] == '.'))
w += ".00";
ll p = ;
for(char c : w) if(isdigit(c))
p = p * + (c - ''); //牛逼
sum += p;
} char buf[];
vector<string> v;
if(sum % != ) {
sprintf(buf, "%02d", (int)(sum % ));
v.push_back(buf);
}
sum /= ;
while(sum >= ) {
sprintf(buf, "%03d", (int)(sum % ));
v.push_back(buf);
sum /= ;
}
v.push_back(to_string(sum)); //to_string() 函数将其他数据类型转化为string/***/http://www.cplusplus.com/reference/string/to_string/ reverse(v.begin(), v.end()); int i = ;
for(string s : v) {
if(i ++ != ) putchar('.');
printf("%s", s.c_str());
}
puts("");
}
return ;
}
CodeForces--TechnoCup--2016.10.15--ProblemB--Bill Total Value(字符串处理)的更多相关文章
- My latest news (--2016.10)
2016.10.31 22:44 一个“程序”,打代码占40%.思考占60% 2016.10.30 20:53 周末,话说今天有晚上讲座,还点名,了,悲催.之前学习的Qt有点问题,悲催.推荐个博文:h ...
- Bill Total Value
Bill Total Value time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Datatables插件1.10.15版本服务器处理模式ajax获取分页数据实例解析
一.问题描述 前端需要使用表格来展示数据,找了一些插件,最后确定使用dataTables组件来做. 后端的分页接口已经写好了,不能修改.接口需要传入页码(pageNumber)和页面显示数据条数(pa ...
- Codeforces Beta Round #10 B. Cinema Cashier 暴力
B. Cinema Cashier 题目连接: http://www.codeforces.com/contest/10/problem/B Description All cinema halls ...
- Codeforces Beta Round #10 A. Power Consumption Calculation 水题
A. Power Consumption Calculation 题目连接: http://www.codeforces.com/contest/10/problem/A Description To ...
- 2016 10 28考试 dp 乱搞 树状数组
2016 10 28 考试 时间 7:50 AM to 11:15 AM 下载链接: 试题 考试包 这次考试对自己的表现非常不满意!! T1看出来是dp题目,但是在考试过程中并没有推出转移方程,考虑了 ...
- 2016.8.15上午纪中初中部NOIP普及组比赛
2016.8.15上午纪中初中部NOIP普及组比赛 链接:https://jzoj.net/junior/#contest/home/1333 这次比赛不怎么好,因为这套题目我并不是很擅长. 可同学们 ...
- 2016.10.4初中部下午NOIP普及组比赛总结
2016.10.4初中部下午NOIP普及组比赛总结 这次的题有些水,只是第四题有点坑. 题目: 比赛:AC+0+AC+50=250 改题:AC+AC+AC+50=350 一.Bill 满地都是水 题目 ...
- 背水一战 Windows 10 (15) - 动画: 缓动动画
[源码下载] 背水一战 Windows 10 (15) - 动画: 缓动动画 作者:webabcd 介绍背水一战 Windows 10 之 动画 缓动动画 - easing 示例演示缓动(easing ...
- Linux Kernel 3.11.4/3.10.15/3.4.65/3.0.99
Linux 今天又发布了4个更新版本,分别是: 3.11.4 2013-10-05 [tar.xz] [pgp] [patch] [view patch] [view inc] [cgit] [cha ...
随机推荐
- 关于python的类方法、实例方法和静态方法区别
python的类方法需要在方法前面加装饰器:@classmethod ,静态方法是在方法前面加装饰器:@staticmethod. 类方法.类属性是属于类自身,属于类自身的命名空间,和实例方法.实例属 ...
- Gentoo: !!! existing preserved libs问题
问题描述 !!! existing preserved libs: >>> package: media-libs/libmng-2.0.2-r1 * - /usr/lib/libm ...
- 创建 .gitignore 文件过滤规
文件 .gitignore 的格式规范如下: 所有空行或者以注释符号 # 开头的行都会被 Git 忽略. 可以使用标准的 glob 模式匹配. 匹配模式最后跟反斜杠(/)说明要忽略的是目录. 要忽略指 ...
- redis高级实用特性(1)
1.安全性 2.主从复制 3.事务处理 4.持久化机制 5.发布订阅消息 6.虚拟内存的使用 安全性:设置客户端连接后进行任何其他指定前需要使用的密码 警告:因为redis速度相当快,所以在一台比较好 ...
- Git一些其它的功能
Git 开始之前我们配置过user.name和user.email.其实还有很多其他的配置项 例如:让Git显示颜色,会让命令输出来更醒目: $ git config --global color.u ...
- Wsyscheck(系统检测维护工具) v1.68.33绿色版
软件名称:系统检测维护工具(Wsyscheck) v1.68.33绿色版软件类别:国产软件运行环境:windows软件语言:简体中文授权方式:免费版软件大小:1022 KB软件等级:整理时间:2011 ...
- 表单提交是ajax提交,PC提交没问题但是手机提交就会一直跳到error,并且也没状态码一直是0
真是被自己蠢死了button标签他会自动提交刷新页面 <form id="baoming_from"> <p>请填写您的个人信息</p> < ...
- ADO.NET 完整修改、删除、防字符串攻击
首先,我先把昨天所做的人事管理系统进行了优化,将其完善成为了一个更符合实际的系统.将修改及删除数据的数据库操作前面添加了一个查询语句,这样,在实际操作时,如果数据库中没有该条数据,则程序不会执行接下来 ...
- Python基础(四)-集合
补充: 数据类型分类: 1.按照数据可变不可变: 可变:列表.字典 不可变:数字.字符串.元组 x={':1} print(id(x)) x.update({':2}) print(x) print( ...
- Linux Ubuntu 14.04安装LAMP(Apache+MySQL+PHP)网站环境
从虚拟主机到VPS/服务器的过度,对于普通的非技术型的站长用户来说可能稍许有一些困难,麦子建议我们如果能够在虚拟主机环境中满足建站需要的, 还是用虚拟主机比较好.除非我们真的有需要或者希望从虚拟主机过 ...