题目
删除字符串中出现次数最少的字符_牛客题霸_牛客网 (nowcoder.com)
C语言
#include <stdio.h>
#include <string.h>
void fun_2024_6_17(void) {
char str[20] = { 0 };
while (scanf("%s", str)!=EOF) {
int alpha[26] = { 0 };
int min = 20;
int len = strlen(str);
for (int _ = 0; _ < len; _++) alpha[str[_] - 'a']++;
for (int _ = 0; _ < 26; _++) if (alpha[_] && alpha[_] < min) min = alpha[_];
for (int _ = 0; _ < len;
_++) if (alpha[str[_] - 'a'] > min) printf("%c", str[_]);
printf("\n");
}
}
int main() {
/*char s[] = "1234";
printf("%s", s + 1);*/
fun_2024_6_17();
return 0;
}
C++
#include <iostream>
#include <string>
#include <vector>
using namespace std;
void fun_2024_6_17(void) {
string s;
vector<int> counter(26, 0);
while (cin >> s) {
for (auto c : s) counter[c - 'a']++;
int m = counter[s[0] - 'a'];
for (auto c : s) if (counter[c - 'a']) m = min(m, counter[c - 'a']);
for (auto c : s) if (counter[c - 'a'] > m) cout << c;
}
}
int main() {
fun_2024_6_17();
return 0;
}
Python
from collections import Counter
def fun_2024_6_17(s):
counter=Counter(s)
minV=min(counter.values())
for e in s:
if counter[e]!=minV:
print(e,end='')
s=input()
fun_2024_6_17(s)
标签:字符,min,int,counter,算法,str,字符串,alpha,include
From: https://blog.csdn.net/weixin_65816128/article/details/139730377