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语音通信 中会遇到的一些问题,阐述可能存在错误,还请多多斧正! 通过设备获取音频流会不可避免的渗入一些杂音,这些杂音可能来自你 ...
随机推荐
- C#实现文件与二进制互转并存入数据库
这篇文章主要介绍了C#实现文件与二进制互转并存入数据库,本文直接给出代码实例,代码中包含详细注释,需要的朋友可以参考下 //这个方法是浏览文件对象 private void button1_C ...
- js最基础的作用域问题
1.什么是作用域? 每个变量和函数,都有其作用的范围,超出这个范围,就不能使用了,这个范围就叫做“作用域”,我们举个例子,一个文件中的变,在另一个文件中直接访问,是访问不到的,两个文件是两个“域”,两 ...
- 初识ADO.NET
摘要 作为.NET框架最重要的组件之一,ADO.NET扮演着应用程序与数据交互的重要的角色.本文将从宏观的角度来探讨ADO.NET,和大家一起了解ADO.NET来龙去脉以及ADO.NET的主要组成部分 ...
- MongoDB:MapReduce基础及实例
背景 MapReduce是个非常灵活和强大的数据聚合工具.它的好处是可以把一个聚合任务分解为多个小的任务,分配到多服务器上并行处理. MongoDB也提供了MapReduce,当然查询语肯定是Java ...
- django的多对一,一对一,多对多关系
from django.db import models class Publisher(models.Model): name = models.CharField(max_length=30) a ...
- 十四、python沉淀之路--文件操作
一.文件操作b模式 1. # f = open('test11.py','rb',encoding='utf-8') # 这种情况会报错 f = open('test11.py','rb') # b ...
- 序列化 SqlAlchemy 的结果为 json 字符串
http://my.oschina.net/gongshang/blog/395431?p=1 在设计 RESTful 的网站时,我们总是希望 ORM 框架返回的结果是可以直接给 View 层使用的 ...
- 【Xamarin】MonoTouch - iOS 使用 UIImagePickerController 打开图片库和相机选择图片修改头像
Application tried to present modally an active controller <UIImagePickerController: 0x7b6ff400> ...
- 限制UITextfield的输入字符为50个字符
1.实现UITextfieldDelegate 2.在UITextfield的代理方法中判断添加字符还是删除字符,从而做不同的操作 #pragma mark-UITextfield的代理方法 - (B ...
- datetimebox
$.extend($.fn.datagrid.defaults.editors, { datetimebox: {// datetimebox就是你要自定义editor的名称 init: functi ...