题解 | #删除字符串中出现次数最少的字符#
删除字符串中出现次数最少的字符
https://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9
#include <stdio.h> #include <string.h> char s[25]; int cnt[26] = {0}; int main() { scanf("%s", s); for (int i = 0; i < strlen(s); i ++ ) { cnt[s[i] - 'a'] ++ ; } int min = 21; for (int i = 0; i <= 26; i ++ ) { if (min > cnt[i] && cnt[i] != 0) min = cnt[i]; } for (int i = 0; i < strlen(s); i ++ ) { if (cnt[s[i] - 'a'] != min) printf("%c", s[i]); } return 0; }