zoukankan      html  css  js  c++  java
  • poj2403

    学会了使用map,

    首先#include <map>,然后声明map<A,B>,map可以当B类型数组用,下标为A类型。成员函数find()可以查找数组中元素,如果没找到返回值为成员函数.end()的值。找到了返回下标。

    View Code
    #include <iostream>
    #include
    <cstdio>
    #include
    <cstdlib>
    #include
    <cstring>
    #include
    <map>
    using namespace std;

    #define maxm 1005

    int m, n;
    string st;
    long long ans;
    map
    <string, int> dict;

    int main()
    {
    //freopen("t.txt", "r", stdin);
    scanf("%d%d", &m, &n);
    ans
    = 0;
    for (int i = 0; i < m; i++)
    {
    cin
    >> st;
    cin
    >> dict[st];
    }
    getchar();
    while (n--)
    {
    ans
    = 0;
    while (cin >> st, st != ".")
    {
    if (dict.find(st) != dict.end())
    ans
    += dict[st];
    }
    cout
    << ans << endl;
    }
    return 0;
    }

  • 相关阅读:
    任务安排(代价提前付)
    10 01模拟赛订正
    哈希hash
    初学期望
    P1251 递推专练3
    P1229-神秘岛
    P1228-重叠的图像
    白银莲花池
    求强连通分量
    割边
  • 原文地址:https://www.cnblogs.com/rainydays/p/2052106.html
Copyright © 2011-2022 走看看