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. 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
  1. 12.4510006
    题解:这题题意是汇率换算,看起来很简单(暴力),但数据量比较大很容易超时.这题需要用到STLmap(当容器中记录有1e6,查询次数也不过20次左右),时间复杂度就减小了。
  1. #include <iostream>
  2. #include <iostream>
  3. #include<string.h>
  4. #include<algorithm>
  5. #include<stdio.h>
  6. #include<stack>
  7. #include<queue>
  8. #include<vector>
  9. #include<math.h>
  10. #include<map>
  11. #define PI acos(-1.0)
  12. using namespace std;
  13. int main()
  14. {
  15. int i,j,m,n,t;
  16. char str[];
  17. double k;
  18. map<string,double>mp;
  19. scanf("%d",&t);
  20. while(t--)
  21. {
  22. scanf("%d%d",&m,&n);
  23. mp.clear();
  24. mp["JD"]=1.0;
  25. double sum=;
  26. for(i=;i<m; i++)
  27. {
  28. scanf("%s%lf",str,&k);
  29. mp[string(str)]=k;
  30. }
  31. for(i=; i<n; i++)
  32. {
  33. scanf("%lf %s",&k,str);
  34. sum+=mp[string(str)]*k;
  35. }
  36. printf("%.6lf\n",sum);
  37. }
  38. return ;
  39. }

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. android xml绘图p113-p117

    1.Bitmap <?xml version="1.0" encoding="utf-8"?> <bitmap xmlns:android=& ...

  2. input type=file 怎么样调取用户手机照相机

    input 有个属性accept="image/*" 这样就可以了,同时在网上看到了其他答案,试了下没啥效果.写记录下来 如下: 使用input:file标签, 去调用系统默认相机 ...

  3. LeetCode OJ:Two Sum(两数之和)

    Given an array of integers, find two numbers such that they add up to a specific target number. The ...

  4. SpringCloud教程 | 第十三篇: 断路器聚合监控(Hystrix Turbine)

    版权声明:本文为博主原创文章,欢迎转载,转载请注明作者.原文超链接 ,博主地址:http://blog.csdn.net/forezp. http://blog.csdn.net/forezp/art ...

  5. Android spannableStringBuilder用法整理

    Android spannableStringBuilder用法整理 分类: Android开发2013-11-29 10:58 5009人阅读 评论(0) 收藏 举报 Androidspannabl ...

  6. wlan接收器如何共享网络

    无线局域网络(Wireless Local Area Networks: WLAN)是相当便利的数据传输系统,它利用射频(Radio Frequency: RF)的技术,取代旧式碍手碍脚的双绞铜线(C ...

  7. NNI (Neurol Network Intelligence) 是微软开源的自动机器学习工具

    NNI (Neurol Network Intelligence) 是微软开源的自动机器学习工具 https://www.cnblogs.com/ms-uap/p/9719071.html [重磅]微 ...

  8. javascript:;与javascript:void(0)

    如果想做一个链接点击后不做任何事情,或者响应点击而完成其他事情,可以设置其属性 href = "#",但是,这样会有一个问题,就是当页面有滚动条时,点击后会返回到页面顶端,用户体验 ...

  9. django保存一个object的时候会发出信号

    当django保存一个object的时候会发出一系列的signals,可以通过对这些signals注册listener,从而相应的signal发出时执行一定的代码. from django.core. ...

  10. openfaas k8s 集成

    备注 k8s 1.6 以下版本与k8s 1.6 以上版本会有一些简单的区别 1. 克隆k8s  部署文档   https://github.com/openfaas/faas-netes   2. 创 ...