2 shunfurh shunfurh 于 2017.09.06 10:28 提问

Bean Counting

The CSC has decided to hold a contest to guess the number of beans in a given jar. To make it a wee bit more interesting, they decided to have the contestants guess the number of a particular kind of bean, the jar having many types of beans in it. Each participant would par $2.00 per guess.
If the guess is one off (either one greater or less) than the actual count, they get a single share of the total pot. If the guess is right on, they get two shares of the total pot.

Your task is to tally these guesses and print out how much each person wins.

Input

The first line will contain hundreds of letters, from a - z, each representing one bean of that type of bean. There will only be 26 different types of beans. The next line contains an integer n, the number of guesses. Each of the n following line will be the guess from a contestant. A contestant can guess as many times as they like. The line will begin with a single letter, in the range A - Z, leaving only 26 possible contests. The first letter will be followed by a single space, and then up to five pairs of letter/number combinations, the letter representing the type of bean for this guess, and the number the number of that bean the contestant expects to find. The letter and the value of a guess will be separated by a ':' and each guess on lines with more than one guess will be separated by a ','.

Process to the end of file.

Tallying:

The amount a contestant will receive is based on shares of a pot. The pot will consist of the total of all the guesses, at $2.00 per guess. The fraction each person gets will be based on:

TotNum: total number of guesses by all contestants
TotShares: total number of shares from all contestants
OffOne: number of off-by-one guesses by that contestant
RightOn: number if right-on guesses by that contestant

(TotNum * $2.00) / TotShares * (OffOne + (RightOn * 2))

Output

Print out all the winners, in alphabetical order, and their winnings, separated by a single space. Each winner should be on a line by itself.

Separate output for different cases by a single blank line.

Sample Input

aadddddddddddddddddddddddffffffffffffffffwwwwwwwwwwwwccccalalala
4
A a:6,c:6
B w:12
C d:25
D d:22,c:4,l:3,f:15

Sample Output

A 3.20
B 3.20
D 9.60

1个回答

caozhy
caozhy   Ds   Rxr 2017.09.20 23:43
已采纳
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
Counting Stars 全中国最准确的翻译!
最近听到Counting Stars这首歌,觉得歌词屌爆了。然后去网上找了找中文翻译,没想到所有我看到的版本都把这首歌翻成了情歌.......还有很多版本的英文歌词都是错的,反正我就没发现全对的。 我想说,亲爱的,这首歌远远不是一首情歌那么简单。 OneRepublic是想通过这首歌描述当下这个已经被金钱绑架的世界,在这样的世界里,人们不再理会自己内心的本意,失去了应有的思考能
pat1004Counting Leaves (30)
题意分析: (1)给出树中节点的总数以及非叶子节点的总数,并给出各非叶子节点的编号、其孩子节点的个数、其孩子节点的编号,求出每一层叶子节点的个数 (2)题意是求出每一层的叶子结点数,其次给出的节点的父子关系很明确,应使用层序遍历的方式 (3)层序遍历过程中存储节点的队列中在front和rear指针之间需要借助一个tag指针,用来标记从front指针到rear指针之间的节点处于同一层,然后开始
Triangle Counting
Description Problem G Triangle Counting Input: Standard Input Output: Standard Output   You are given n rods of length 1, 2…, n. You have to pick any 3 of them & build a triangle. How many
[leetcode] 338. Counting Bits
Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array. Example: For num = 5
[POJ2386][OpenJudge] 2.5基本算法之搜索 Lake Counting
一、原题 描述 Due to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 <= N <= 100; 1 <= M <= 100) squares. Each square contains ei
[leetcode-338]Counting Bits(java)
原文地址:https://leetcode.com/problems/counting-bits/分析:这道题要求给定N,然后计算从0到N之间所有的数的bit为1的数,并要求时间复杂度为O(N),因此对于每个数,然后求它的bit数的方法是不可取的。 所幸,当我们把数从0到N写出来时很容易发现规律,即对于2^N的数,末尾N-1位的重复规律,正好等于前N-1个数的重复规律,而这时只需要加1即可。pub
PAT甲级 1004.Counting Leaves (30) 题目翻译与答案
1004.计算叶子个数 一个家庭的层级结构经常被表现为一个家谱树。你的任务是统计这些家庭成员中谁没有孩子。 输入 每个输入文件包含一个测试实例。每个实例开始的一行包含N和M,N指树中的结点个数(0<N<100),M指非叶结点的个数。然后下面有M行,每行的格式如下:
深度优先搜索的用法——lake counting
深度优先搜索的用法——lake counting 问题主题:Lake Counting 问题描述: 有一个大小为N*M的园子,雨后积了很多水。八连通的积水被认为是在一起的。请求出园子里共有多少个水洼?(八连通是指下图中相对+的*部分) +++ +*+ +++ 限制条件: N,M  样例: 输
【PAT 1049】 Counting Ones 数学规律
1049. Counting Ones (30) 时间限制 10 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The task is simple: given any positive intege
d-Left Counting Bloom Filter (1)
哈希函数的输出值(hash value)通常有两种用途:一种用作地址,比如在哈希表中要存储一个元素,首先要针对这个元素生成一个随机地址;另一种用作fingerprint(或者叫digital summary),比如将密码字符串hash成一个fingerprint,验证时进行核对。今天我要介绍的这种存储信息的方式将以上两种用途结合了起来:一个hash value分作两部分,一部分用作存储地址,另