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. make和makefile介绍

    <strong>先附上一个比较简单的,测试代码用的Makefile</strong> </pre><pre code_snippet_id="463 ...

  2. Every derived table must have its own alias

    完整错误信息如下: Every derived table must have its own alias 三月 28, 2017 10:20:46 上午 org.apache.catalina.co ...

  3. 可视化CNN神经网路第一层参数

    在上Andrew Ng的课的时候搜集到了课程里面自带的显示NN参数的代码,但是只能显示灰度图,而且NN里的参数没有通道的概念.所以想要获得可视化CNN的参数,并且达到彩色的效果就不行了. 所以就自己写 ...

  4. Java中最常见的十道面试题

    第一,谈谈final, finally, finalize的区别. final?修饰符(关键字)如果一个类被声明为final,意味着它不能再派生出新的子类,不能作为父类被继承.因此一个类不能既被声明为 ...

  5. 伪元素:placeholder-shown&&:focus-within

    :placeholder-shown 另外,划重点,这个伪类是仍处于实验室的方案.也就是未纳入标准,当然我们的目的是探寻有意思的 CSS . 当 input 类型标签使用了 placeholder 属 ...

  6. Android的长度单位及屏幕分辨率

    屏幕分辨率基础 1.术语和概念 术语 说明 备注 Screen size(屏幕尺寸) 指的是手机实际的物理尺寸,比如常用的2.8英寸,3.2英寸,3.5英寸,3.7英寸 摩托罗拉milestone手机 ...

  7. c++11新特性之宽窄字符转换

    C++11增加了unicode字面量的支持,可以通过L来定义宽字符:str::wstring str = L"中国人": 将宽字符转换为窄字符串需要用到codecvt库中的std: ...

  8. LeetCode Design TinyURL

    原题链接在这里:https://leetcode.com/problems/design-tinyurl/description/ 题目: How would you design a URL sho ...

  9. Python reload() 函数

    reload(module) 作用: 用于重新载入之前载入的模块. module -- 模块对象.返回模块对象. 实例:  重新载入 sys 模块,并设置默认编码为 utf8 >>> ...

  10. vue-cli结构

    |-- build // 项目构建(webpack)相关代码 | |-- build.js // 生产环境构建代码 | |-- check-version.js // 检查node.npm等版本 | ...