• 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.451000
    用暴力会时间超限,所以用MAP

    #include <iostream>

    #include <algorithm>
    using namespace std;
    #include <stdio.h>
    #include <string.h>
    #include <map>
    int main()
    {
        int t,m,n,k,i;
        char c[15];
        double x,ans=0,a;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d%d",&n,&m);
            map<string,double> mp;
            for(i=0;i<n;i++)
            {
                scanf("%s",c);
                scanf("%lf",&x);
                mp[string(c)]=x;
            }
            mp["JD"]=1.0;
            ans=0;
            for(i=0;i<m;i++)
            {
                scanf("%lf",&a);
                scanf("%s",c);
                ans+=mp[string(c)]*a;
            }
            printf("%lf ",ans);
        }
        return 0;
    }
  • 相关阅读:
    php+mysql折线图
    转载] magento 产品数据表结构
    magento 开启模板路径提示
    magento smtp设置
    magento 搬家
    利用DIV+CSS制作网页过程中常用的基本概念及标签使
    使用CSS创建有图标的网站导航菜单
    在网页中使用H1标记的须注意的事项
    兼容firefox的iframe高度自适应代码
    jQuery: 图片不完全按比例自动缩小
  • 原文地址:https://www.cnblogs.com/zcy19990813/p/9702812.html
Copyright © 2020-2023  润新知