zoukankan      html  css  js  c++  java
  • STL之map

    描述

    使用STL中的map,查找字符串出现的次数。

    部分代码已经给出,请补充完整,提交时请勿包含已经给出的代码。

     

    int main()
    {
        int m;
        map<string, int> sm;
        Input(sm);
        cin>>m;
        while(m--)
        {
            string s;
            cin>>s;
            cout<<sm[s]<<endl;
        }
        return 0;
    }

    输入

    输入数据第一行为正整数n,接下来包含n行,每行一个字符串,表示字符串列表。

    接下来有m行,每行一个字符串,表示要查找的字符串。

    字符串均不含空格。

    输出

    查找每个字符串在字符串列表中出现的次数。

    样例输入

     5
    abc
    def
    abc
    def
    abc
    3
    abc
    def
    hello

    样例输出

     3
    2
    0

    #include <iostream>
    #include <queue>
    #include <vector>
    #include <map>
    #include <string>
    #include <functional>
    #include <deque>
    using namespace std;
    void Input(map<string , int > &sm)
    {
        int n;
        cin>>n;
        while(n--)
        {
            string s;
            cin>>s; 
            sm[s]++;
        }
    }
    int main()
    {
        int m;
        map<string, int> sm;
        Input(sm);
        cin>>m;
        while(m--)
        {
            string s;
            cin>>s;
            cout<<sm[s]<<endl;
        }
        return 0;
    }

     

  • 相关阅读:
    [bzoj1113][Poi2008]海报PLA
    [CF1111D]Destroy the Colony
    [CF1111E]Tree
    [CF1111C]Creative Snap
    [洛谷P5136]sequence
    [洛谷P5190][COCI 2010] PROGRAM
    [洛谷P5137]polynomial
    US Open 2016 Contest
    【hackerrank】Week of Code 26
    usaco中遇到的问题
  • 原文地址:https://www.cnblogs.com/andrew3/p/8724164.html
Copyright © 2011-2022 走看看