【AtCoder】ABC 447 B - mpp
https://atcoder.jp/contests/abc447/tasks/abc447_b
atcoder.jp
実行時間制限: 2 sec / メモリ制限: 1024 MiB / Difficulty: 50 / NoviSteps: 6Q / 配点: 100 点
問題概要
英小文字からなる文字列 が与えられる。 の中で出現回数が最も多い文字をすべて取り除き、残った文字を元の順序を保ったまま連結して出力せよ。 出現回数が最大の文字が複数種類ある場合は、そのすべてを取り除くこと。
制約
考察
の各文字をmapに突っ込み、valueの最大値を求める。
その後、 を先頭から走査し、出現回数が最大でない文字を出力していく。
実装例
CPP
1.#include <bits/stdc++.h>2.using namespace std;3. 4.template <typename T>5.inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }6. 7.// ======================================== //8. 9.int main()10.{11. string S;12. cin >> S;13. 14. map<char, int> mp;15. for (auto c : S)16. mp[c]++;17. 18. int max_cnt = 0;19. for (auto [_, cnt] : mp)20. chmax(max_cnt, cnt);21. 22. string ans;23. for (auto c : S)24. {25. if (mp[c] != max_cnt)26. ans += c;27. }28. 29. cout << ans << endl;30. 31. return 0;32.}https://atcoder.jp/contests/abc447/submissions/73681209
atcoder.jp
実装時間: 5 分以内
コメント
まあやるだけといったところ。





