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

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

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

#include <stdio.h>
#include<string.h>
#include<stdlib.h>

int main() {
   char str[21]={0};
   int hash[26]={0};
   scanf("%s",str);
   int len=strlen(str);
   int cnt=0;
   int min=20;
   for(int i=0;i<len;i++){
      hash[str[i]-'a']++;
   }
   
   for(int i=0;i<26;i++){
    if(hash[i]!=0&&hash[i]<min){
        min=hash[i];
    }
   }

   for(int j=0;j<len;j++){
    if(hash[str[j]-'a']>min){
        printf("%c",str[j]);
    }
    else continue;
   } 
   return 0;
}

全部评论

相关推荐

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

创作者周榜

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