【统计难题】【HDU - 1251】【map打表或字典树】【字典树模板】
思路 题意 : 题目 为中文题,这里不再过多阐述。 思路1 :可以在读入单词表的过程中将单词分解,用map将它一 一记录 思路2 :利用字典树,这个方法较快些,下面代码中会分别给出数组和结构体指针两种形式的字典树,指针形式的有时可能会因题目内存限制而导致Memory Limit Exceeded,这时就可选择数组形式的。不过对于本题来说不用担心。 AC代码 代码1:map打表 #include<bits/stdc++.h> using namespace std; typedef long long LL; map<string, int> table; int main() { std::ios::sync_with_stdio(false); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); table.clear(); string s; while(getline(cin, s)) { if(s[0] == '\0') break; string ss = ""; for(int i = 0; i < s.size(); i++) { ss += s[i]; table[ss]++; } } while(cin >> s) { cout << table[s] <<