公式
B - mpp 解説 by en_translator
It is sufficient to implement as instructed in the problem statement. Among the several possible approaches, the following implementation adopts the following one:
- Construct a frequency array (that manages how many times each letter occurs in \(S\)).
- Find the maximum value in the frequency (= maximum frequency).
- Concatenate the characters that do not take the maximum.
Sample code in Python:
s = input()
cnt = {c : s.count(c) for c in s}
ma = max(cnt.values())
print("".join(c for c in s if cnt[c] != ma))
Sample code in C++
#include <bits/stdc++.h>
using namespace std;
int main(){
string s; cin >> s;
vector<int> cnt(26, 0);
for (char c : s) cnt[c-'a']++;
int ma = *max_element(cnt.begin(), cnt.end());
string t = "";
for (char c : s){
if (cnt[c-'a'] != ma) t += c;
}
cout << t << endl;
}
投稿日時:
最終更新: