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

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

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

#include <cstdio>
#include <cstring>
using namespace std;
int main() {
    char arr[21];
    int len;
    int minCnt;
    int nums[26];
    while(EOF != scanf("%s", arr)) {
        getchar();
        minCnt = 100;
        memset(nums, 0, sizeof(nums));
        len = strlen(arr);
        for(int i = 0; i < len; i++) {
            nums[arr[i] - 'a']++;
        }
        for(int i = 0; i < 26; i++) {
            if(nums[i] != 0 && nums[i] < minCnt) {
                minCnt = nums[i];
            }
        }
        for(int i = 0; i < len; i++) {
            if(nums[arr[i] - 'a'] != minCnt) {
                printf("%c", arr[i]);
            }
        }
        printf("\n");
    }
    return 0;
}
全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务