题解 | #删除字符串中出现次数最少的字符#
删除字符串中出现次数最少的字符
https://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9
/*********** *先存储再查找最小次数,最后剔除输出 ************/ #include <stdio.h> #include <string.h> int main() { char str[21]; while( scanf( "%s", str ) != EOF ) { int flag[26] = {0}; int min = 20; int len = strlen(str); for( int i = 0; i<len; i++ ) { flag[str[i] - 'a']++; } for( int i = 0; i<26; i++ ) { if( flag[i] && flag[i] < min ) min = flag[i]; } for( int i = 0; i<len; i++ ) { if( flag[str[i] - 'a'] > min ) printf( "%c", str[i] ); } printf("\n"); } return 0; }