UVa 11340 Newspaper
来源:互联网 发布:知乎飞机杯 编辑:程序博客网 时间:2024/05/01 16:37
News agency pays money for articles according to some rules. Each character has its own value (somecharacters may have value equals to zero). Author gets his payment as a sum of all character’s valuesin the article. You have to determine the amount of money that news agency must pay to an author.
Input
The first line contains integerN (0< N ≤5), it is a number of tests. Each test describes an integerK(0 < K≤ 100), the number of paid characters. On nextK lines there are table of paid charactersand its values (character values are written in cents). If character can not be found in the table, thenits value is equal to zero. Next, there is integer M(0 < M≤ 150000). NextM lines contain an articleitself. Each line can be up to 10000 characters length. Be aware of a large input size, the whole inputfile is about 7MB.
Output
For each test print how much money publisher must pay for an article in format ‘x.yy$’. Where x isa number of dollars without leading zeros, andyy number of cents with one leading zero if necessary.Examples: ‘3.32$’, ‘13.07$’, ‘71.30$’, ‘0.09$’.
Sample Input
1
7
a3
W 10
A 100
, 10
k7
.3
I 13
7
ACM International Collegiate Programming Contest (abbreviated
as ACM-ICPC or just ICPC) is an annual multi-tiered competitionamong the universities of the world. The ICPC challenges studentsto set ever higher standards of excellence for themselves
through competition that rewards team work, problem analysis,
and rapid software development.
From Wikipedia.
Sample Output
3.74$
题目描述:字符有数值,给一串文本,求字符数值之和。因文件较大,使用getchar()读入。注意C++标准中char可能是unsigned也可能是signed。这题的字符需要使用unsigned char,不然会WA。运行时间30ms。
/*PROG: UVa11340*/#include <cstdio>#include <cstring>#include <cctype>using namespace std;int val[300];typedef long long LL;#define DEBUG 0#define LOG(...) do { if (DEBUG) fprintf(stderr, __VA_ARGS__); } while(0)int main(void) {int Z; scanf("%d", &Z);for (int z = 0; z < Z; ++z) {int n; scanf("%d", &n);getchar();memset(val, 0, sizeof(val));for (int i = 0; i < n; ++i) {unsigned char ch = getchar();int v; scanf("%d", &v);val[ch] = v;getchar();}LOG("val done\n");int m; scanf("%d", &m);getchar();LL ans = 0;while (m) {unsigned char ch = getchar();LOG("%c", ch);ans += val[ch];if (ch == '\n') --m;}printf("%lld.%02lld$\n", ans/100, ans%100);}return 0;}
- UVa 11340 - Newspaper
- Uva Oj 11340 - Newspaper
- UVa 11340 Newspaper
- UVa 11340 Newspaper (water ver.)
- 11340 - Newspaper
- Newspaper
- Newspaper and Magazine
- hundred Chinese {newspaper} site
- Barron's (newspaper)
- scrapy newspaper bug
- Codeforces 91A-Newspaper Headline
- UVA11340 Newspaper【输入流+map】
- 给定两个字符串newspaper和message,检查是否能够使用newspaper中的字母来组成message
- How to Read the Newspaper Quickly and Efficiently
- Better modelling and visualisation of newspaper count data
- Newspaper v7.5 新闻 WordPress主题 免费下载
- 四十二天学会英语的模范短文01--THE NEWSPAPER 报 纸
- Qt5:LNK2001: 无法解析的外部符号 "public: static struct QMetaObject const Newspaper::staticMeta
- 利用scikit-learn进行人脸表面关键点的定位
- 图片鉴黄的原理和应用
- Android之用sharedUserId来实现不同应用(APK)数据共享
- Xcode常见警告汇总(持续更新)
- React Native填坑之旅--组件生命周期
- UVa 11340 Newspaper
- 完美方案——iOS的WebView自适应内容高度
- 深入理解Android输入系统
- MyBatis的foreach语句详解
- python的UML类图自动生成工具--pyreverse安装和使用
- This application is modifying the autolayout engine from a background thread after 。。。
- nyoj 找球号(二)
- Android命名规范
- android 点滴成长