zoukankan      html  css  js  c++  java
  • 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?

    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次左右),时间复杂度就减小了。

     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[22];
    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=0;
    26         for(i=0;i<m; i++)
    27         {
    28             scanf("%s%lf",str,&k);
    29             mp[string(str)]=k;
    30         }
    31         for(i=0; i<n; i++)
    32         {
    33             scanf("%lf %s",&k,str);
    34             sum+=mp[string(str)]*k;
    35         }
    36         printf("%.6lf
    ",sum);
    37     }
    38     return 0;
    39 }
  • 相关阅读:
    Ant-编译构建(2)-第3方jar包引入、log4j2
    Ant-编译构建(1)-HelloWorld
    java List的初始化
    传入json字符串的post请求
    HttPclient 以post方式发送json
    cron表达式详解,cron表达式写法,cron表达式例子
    深入理解SQL的四种连接-左外连接、右外连接、内连接、全连接
    Java两种延时——thread和timer
    List<List<Object>> list = new ArrayList<List<Object>>(); 求回答补充问题 list.get(position).add(Object);为什么会报错啊我想在对应的list里面添加对象
    关于 charset 的几种编码方式
  • 原文地址:https://www.cnblogs.com/moomcake/p/8921374.html
Copyright © 2011-2022 走看看