(记录第一次笔试
T1(模拟、哈希表)
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<string, int> PSI;
const int N = 1e5 + 10;
void solve() {
string line, t;
getline(cin, line);
line += ' ';
vector<PSI> ans;
unordered_map<string, int> cnt;
for(int i = 0; i < line.size(); i ++) {
if(line[i] == ' ') cnt[t] ++ , t = "";
else t += line[i];
}
for(auto kv : cnt) {
if(kv.second >= 3) ans.push_back(make_pair(kv.first, kv.second));
}
sort(ans.begin(), ans.end(), [](PSI& a, PSI& b) {
if(a.second != b.second) return a.second > b.second;
return a.first < b.first;
});
for(auto ss : ans) cout << ss.first << endl;
}
int main() {
cin.tie(0); cout.tie(0);
std::ios::sync_with_stdio(false);
int T = 1;
// cin >> T;
while(T --) {
solve();

本文介绍了在一次编程笔试中遇到的三个问题:使用哈希表解决字符串计数,01背包问题的动态规划解法,以及涉及树形结构的动态规划问题。展示了C++代码实现和解题思路。
最低0.47元/天 解锁文章
7940

被折叠的 条评论
为什么被折叠?



