I don't know where my code went wrong, I got two correct answers and 8 wrong answers, thanks in advance for any help.
A word is defined as a string of w characters from a alphabet S.
A document is defined as a sequence of words.
Given n documents D:=(Di)i=1~n where each document is of mi words.
Document counting is to count number of documents where a word occurs when the word is given.
There will be document counting queries.
Input Format
The 1st line is n.
The following 2n lines are documents, where the 1st and 2nd line of every 2 lines are mi and Di.
The following line is q .
The following q lines are words for document counting query.
Output Format
Output m lines of response for document counting queries.
Sample Input 0
5
2
A AB
1
A
3
A AB ABC
5
A AB ABC ABCD ABCDE
4
A AB ABC ABCD
3
AB
C
ABCDE
Sample Output 0
4
0
1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <unordered_map>
#include <map>
using namespace std;
int main() {
uint64_t n;
cin>>n;
map<string, uint64_t> table;
while(n--)
{
uint64_t a;
cin>>a;
while(a--)
{
string N;
cin >> N;
table[N]++;
}
}
uint64_t q;
cin>>q;
while (q--)
{
string key;
cin >> key;
if (table.find(key) != table.end()) { cout << table[key] << "\n"; }
else { cout << "0\n"; }
}
return 0;
}
|