Every year, an elephant qualifies to the Arab Collegiate Programming Competition. He graduated this year, but that’s irrelephant. What’s important is that the location of the competition might not have been the same every year. Therefore, after every trip, he always has leftover money in the currency of the country he visited.

Now he wants to see how much Jordanian Dinars he has after all those competitions. Can you help him convert the leftover money from all competitions to Jordanian Dinar, if that makes any cents?

Input

The first line of input is T – the number of test cases.

The first line of each test case contains C and N (1 ≤ C, N ≤ 100000), the number of currency types and the number of competitions, respectively.

The next C lines each contain the name of the currency Ci of maximum length 10 in lowercase and/or uppercase letters, and the value Vi of that currency in Jordanian Dinar (0 < Vi ≤ 1000). The names are case-sensitive.

The next N lines each contains an amount left over from each competition (0 ≤ Ni ≤ 1000), and the name of the currency of that amount (it is guaranteed that the name was either given in the input or is “JD”).

Output

For each test case, print on a single line the total amount of money he has in Jordanian Dinar(JD) rounded to 6 decimal digits.

Example
Input

Copy
1
3 5
dollar 0.71
euro 0.76
turkish 0.17
5.1 dollar
6 dollar
7 turkish
3 euro
1.1 JD
Output

Copy
12.4510006
题解:这题题意是汇率换算,看起来很简单(暴力),但数据量比较大很容易超时.这题需要用到STL中map(当容器中记录有1e6,查询次数也不过20次左右),时间复杂度就减小了。
 #include <iostream>
#include <iostream>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<stack>
#include<queue>
#include<vector>
#include<math.h>
#include<map>
#define PI acos(-1.0)
using namespace std;
int main()
{
int i,j,m,n,t;
char str[];
double k;
map<string,double>mp;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&m,&n);
mp.clear();
mp["JD"]=1.0;
double sum=;
for(i=;i<m; i++)
{
scanf("%s%lf",str,&k);
mp[string(str)]=k;
}
for(i=; i<n; i++)
{
scanf("%lf %s",&k,str);
sum+=mp[string(str)]*k;
}
printf("%.6lf\n",sum);
}
return ;
}

Make Cents的更多相关文章

  1. [CareerCup] 9.8 Represent N Cents 美分的组成

    9.8 Given an infinite number of quarters (25 cents), dimes (10 cents), nickels (5 cents) and pennies ...

  2. Cents os 7下如何安装bzip2

    # Cents os 7下如何安装bzip2 ### 安装```yum search bzip2  //查询安装包 yum -y install bzip2.x86_64 ``` ### 原因---- ...

  3. [CareerCup] 9.8 Represent N Cents 组成N分钱

    9.8 Given an infinite number of quarters (25 cents), dimes (10 cents), nickels (5 cents) and pennies ...

  4. cents上运行wget报错:unable to resolve host address

    wget命令报错.无法解析域名"www.keepalived.rog" [vagrant@RS1 download]$ wget http://www.keepalived.org ...

  5. Cent OS (一)Cents OS的基本安装

    1.实验环境: VMware Workstation Pro   14 Pro Cent OS 7 系列. 2. 镜像地址传送门: 阿里云开源镜像站:http://mirrors.aliyun.com ...

  6. Core Java 总结(数据类型,表达式问题)

    2016-10-18 整理 写一个程序判断整数的奇偶 public static boolean isOdd(int i){ return i % 2 == 1; } 百度百科定义:奇数(英文:odd ...

  7. [LeetCode] Coin Change 硬币找零

    You are given coins of different denominations and a total amount of money amount. Write a function ...

  8. Vue - 内部指令

    1.插值 A:<span>TEXT:{{text}}</span> {{text}}会被相应的数据类型text属性值替换,当text值改变时候,文本中的值也会相应的发生变化 B ...

  9. [Voice communications] 声音的滤波

    本系列文章主要是介绍 Web Audio API 的相关知识,以及 web语音通信 中会遇到的一些问题,阐述可能存在错误,还请多多斧正! 通过设备获取音频流会不可避免的渗入一些杂音,这些杂音可能来自你 ...

随机推荐

  1. L136

    Newly formed blood vessels may contribute to eye disease: studyA study of Northwestern University (N ...

  2. jquery 中多条件选择器,相对选择器,层次选择器的区别

    一.Jquery常用的过滤选择器如下所示: 1.:first,选取第一个元素,比如$("div:first")选取第一个div元素 2.:last,选取最后一个元素,比如$(&qu ...

  3. Head First HTML与CSS 学习笔记

    1.使用<a>元素创建一个超文本链接,链接到另一个Web页面.<a>元素的内容会成为Web页面中可单击的文本.href属性告诉浏览器链接的目标文件. 2.块元素特立独行,内联元 ...

  4. 使用flowable 6.1.2 REST API 运行请假审批流程

    一.下载 flowable rest war 包 http://download.csdn.net/detail/teamlet/9913312 二.部署 复制flowable REST.war到To ...

  5. angualr4 环境搭建

    不得不说现在很流行前端MVC框架,angularjs算是一种.以前也用过angularjs感觉还不错,刷新了我对前端的认知.特别是因为我本身是个java开发.但是感觉还是有很多缺点的,直到angula ...

  6. 【MFC】MFC绘图不闪烁——双缓冲技术

    MFC绘图不闪烁——双缓冲技术[转] 2010-04-30 09:33:33|  分类: VC|举报|字号 订阅 [转自:http://blog.163.com/yuanlong_zheng@126/ ...

  7. SQLServer流水号自动生成

    最近给客户做生成条码的功能时,碰到个问题,需要根据数量自动生成流水号,然后加上客户指定的前缀,组合成条码. 折腾了一会,最后通过个存储过程实现. --@Prefix 指定前缀,@InitialVal ...

  8. NSArray倒序输出的方法

    NSMutableArray *array = [NSMutableArray arrayWithObjects:",nil]; NSArray* reversedArray = [[arr ...

  9. AtCoder Grand Contest 017 题解

    A - Biscuits 题目: 给出 \(n\) 个物品,每个物品有一个权值. 问有多少种选取方式使得物品权值之和 \(\bmod\space 2\) 为 \(p\). \(n \leq 50\) ...

  10. (转)setTextColor()的参数设置方式

    setTextColor()的参数设置方式 分类: Android界面研究2011-12-09 23:27 11160人阅读 评论(2) 收藏 举报 查了下资料发现setTextColor()的参数应 ...