zoukankan      html  css  js  c++  java
  • CodeForces Gym-101350M

    M. Make Cents?

    time limit per test

    6.0 s

    memory limit per test

    256 MB

    input

    standard input

    output

    standard output

    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 Viof 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
    做这题就会深深地体会到STL的map容器灰常的好用了。题目很简单,掌握map用法就会做了;
    代码如下:
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    #include <cmath>
    #include <map>
    #include <string>
    #include <algorithm>
    #define maxn 100010
    using namespace std;
    int main(){
        int t;
        map<string, double> mp;
        int c, n;
        double sum;
        string str1;
        string str2;
        double v1, v2;
        cin >> t;
        while (t--){
            cin >> c >> n;
            for (int i = 0; i < c; i++){
                cin>>str1;
                cin >> v1;
                mp[str1] = v1;
            }
            mp["JD"] = 1;
            sum = 0;
            for (int i = 0; i < n; i++){
                cin >> v2;
                cin>>str2;
                sum += mp[str2] * v2;
            }
            printf("%.6f
    ", sum);
        }
        return 0;
    }

    插入一个我觉得写的挺好的关于map容器的详细讲解链接,最好自己写个代码都用一用就熟练了。

    https://www.cnblogs.com/Braveliu/p/6427050.html

    天晴了,起飞吧
  • 相关阅读:
    正则二三事
    docker elasticsearch 5.6.13 安装ik分词器
    centos docker 防火墙设置(多个ip之间互相访问)
    ElasticSearch结构化搜索和全文搜索
    Jest — ElasticSearch Java 客户端
    提高redis cluster集群的安全性,增加密码验证
    spring boot 设置 gzip 压缩
    centos 7磁盘空间满了导致redis cluster问题和kafka的问题
    SpringBoot之MySQL数据的丢失的元凶--事务(转)
    mysql mycat 1.6.6.1-release 批量 insert 数据丢失问题(续)
  • 原文地址:https://www.cnblogs.com/jianqiao123/p/11296830.html
Copyright © 2011-2022 走看看