Make Cents
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?
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”).
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.
1
3 5
dollar 0.71
euro 0.76
turkish 0.17
5.1 dollar
6 dollar
7 turkish
3 euro
1.1 JD
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的更多相关文章
- [CareerCup] 9.8 Represent N Cents 美分的组成
9.8 Given an infinite number of quarters (25 cents), dimes (10 cents), nickels (5 cents) and pennies ...
- Cents os 7下如何安装bzip2
# Cents os 7下如何安装bzip2 ### 安装```yum search bzip2 //查询安装包 yum -y install bzip2.x86_64 ``` ### 原因---- ...
- [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 ...
- cents上运行wget报错:unable to resolve host address
wget命令报错.无法解析域名"www.keepalived.rog" [vagrant@RS1 download]$ wget http://www.keepalived.org ...
- Cent OS (一)Cents OS的基本安装
1.实验环境: VMware Workstation Pro 14 Pro Cent OS 7 系列. 2. 镜像地址传送门: 阿里云开源镜像站:http://mirrors.aliyun.com ...
- Core Java 总结(数据类型,表达式问题)
2016-10-18 整理 写一个程序判断整数的奇偶 public static boolean isOdd(int i){ return i % 2 == 1; } 百度百科定义:奇数(英文:odd ...
- [LeetCode] Coin Change 硬币找零
You are given coins of different denominations and a total amount of money amount. Write a function ...
- Vue - 内部指令
1.插值 A:<span>TEXT:{{text}}</span> {{text}}会被相应的数据类型text属性值替换,当text值改变时候,文本中的值也会相应的发生变化 B ...
- [Voice communications] 声音的滤波
本系列文章主要是介绍 Web Audio API 的相关知识,以及 web语音通信 中会遇到的一些问题,阐述可能存在错误,还请多多斧正! 通过设备获取音频流会不可避免的渗入一些杂音,这些杂音可能来自你 ...
随机推荐
- LeetCode OJ:Spiral Matrix(螺旋矩阵)
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral or ...
- Java.lang包的接口解读
Java.lang包中提供了八个接口: 1.Appendable 能够被追加 char 序列和值的对象.如果某个类的实例打算接收来自 Formatter的格式化输出,那么该类必须实现 Appendab ...
- Android的方法和属性(2)
1.RadioButton(单选按钮) 嵌入到RsdioGroup中实现单选效果 android:checkedButton="radio的id值" int getCheckedR ...
- 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 ...
- c++指针初探
业余时间准备重温一下c++,因为在阅读Android源码到native层的时候感觉有点吃力,只是在大学时候很不用心的学过c++,所以重温下以便打好一些编程基础知识,本篇就很简单的对c++的指针做初步的 ...
- toString 和 valueOf 总结
两者的共同点与不同点: 共同点:二者都能用来数据转换,并且在输出对象时会自动调用. 不同点:二者并存的情况下,在数值运算中,优先调用了valueOf,字符串运算中,优先调用了toString,没有操作 ...
- 年终盘点:Java今年的大事记都在这里!
在2017年即将结束之际,我们最好停下脚步来看看过去十二个月Java的发展情况.本文,笔者盘点了IT168企业级一年来对Java的跟踪报道. 这一年对Java来说是不容易的,从Java 9一再延期备受 ...
- InpOutx64 替代 winIOx64
/***************************************************************************** * InpOutx64 替代 winIOx ...
- linux下 /boot 分区空间不足及其衍生问题
linux的/boot引导分区有时会提示空间不足的问题,虽不影响系统的正常运行,但是人类天生对于未知的恐惧感总是影响心情的.而且在按安装其他软件的过程在中可能会出现以下问题: gzip: stdout ...
- 在spring配置文件中的 <context:property-placeholder/>用途
location属性为 具体配置文件的classpath:地址 (可以取配置文件中的值利用${key}的形式,而不用多次写值) 1.这样一来就可以为spring配置的bean的属性设置值了,比如spr ...