Cerinta completa

There is a collection of input strings and a collection of query strings. For each query string, determine how many times it occurs in the list of input strings. Return an array of the results.

Example


There are instances of ‘‘, of ‘‘, and of ‘‘. For each query, add an element to the return array: .

Function Description

Complete the function with the following parameters:

  • : an array of strings to search
  • : an array of query strings

Returns

  • : the results of each query

Input Format

The first line contains and integer , the size of .
Each of the next lines contains a string .
The next line contains , the size of .
Each of the next lines contains a string .

Constraints



.


Limbajul de programare folosit: cpp14

Cod:

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;


int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
    map<string,int> count;
    int n;
    cin>>n;
    while(n--){
        string s;
        cin>>s;
        count[s]++;
    }
    cin>>n;
    while(n--){
        string s;
        cin>>s;
        //cout<<s<<endl;
        cout<<count[s]<<endl;
    }
    return 0;
}

Scor obtinut: 1.0

Submission ID: 464651324

Link challenge: https://www.hackerrank.com/challenges/sparse-arrays/problem

Sparse Arrays