题解 | #删除字符串中出现次数最少的字符#

删除字符串中出现次数最少的字符

https://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9

#include <stdio.h>
#include <string.h>
int main() {
    int chs[30] = {0};
    char str[30] = {0};
    int strLen = 0;
    scanf("%s",str);
    strLen = strlen(str);
    for(int i = 0; i < strLen; i++)
    {
        chs[str[i] - 'a']++;
    }
    int minNum = -1;
    for(int i = 0; i < 30; i++)
    {
        if(chs[i] > 0)
        {
            if(-1 == minNum)
                minNum = chs[i];
            else if(minNum > chs[i])
                minNum = chs[i];
        }
    }

    for(int i = 0; i < strLen; i++)
    {
        if(chs[str[i] - 'a'] != minNum)
            printf("%c",str[i]);
    }
    return 0;
}

全部评论

相关推荐

评论
点赞
收藏
分享
牛客网
牛客企业服务