UVa 11340 Newspaper (water ver.)

11340 - Newspaper

Time limit: 1.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2315

News agency pays money for articles according to some rules. Each character has its own value (some characters may have value equals to zero). Author gets his payment as a sum of all character's values in the article. You have to determine the amount of money that news agency must pay to an author.

INPUT:
The first line contains integer N (0 < N <= 5), it is a number of tests. Each test describes an integer K (0 < K <= 100), the number of paid characters. On next K lines there are table of paid characters and its values (character values are written in cents). If character can not be found in the table, then its value is equal to zero. Next, there is integer M (0 < M <= 150000). Next M lines contain an article itself. Each line can be up to 10000 characters length. Be aware of a large input size, the whole input file is about 7MB.

OUTPUT:
For each test print how much money publisher must pay for an article in format " x.yy$ ". Where " x " is a number of dollars without leading zeros, and " yy " number of cents with one leading zero if necessary. Examples: " 3.32$ ", " 13.07$ ", " 71.30$ ", " 0.09$ ".

SAMPLE INPUT:
1
7
a 3
W 10
A 100
, 10
k 7
. 3
I 13
7
ACM International Collegiate Programming Contest (abbreviated
as ACM-ICPC or just ICPC) is an annual multi-tiered competition
among the universities of the world. The ICPC challenges students
to 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$

直接开个130大小的数组把char对应的值存起来~


/*0.036s*/

#include<cstdio>
#include<cstring>

int ch[130];
char str[10005];

int main()
{
	int n, k, val, m, len, i;
	long long sum;
	char c;
	scanf("%d", &n);
	while (n--)
	{
		memset(ch, 0, sizeof(ch));
		scanf("%d\n", &k);
		while (k--)
		{
			c = getchar();
			scanf("%d\n", &val);
			ch[c] = val;
		}
		scanf("%d\n", &m);
		sum = 0;
		while (m--)
		{
			gets(str);
			len = strlen(str);
			for (i = 0; i < len; ++i)
				sum += ch[str[i]];
		}
		printf("%.2f$\n", (double)sum / 100);
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值