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

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

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

这题我感觉用暴力最直接。主要是统计出出现最小的字符的次数,找出来,输出的时候,只需要将出现次数大于最小次数的输出即可。

#include<algorithm>
#include<string>
using namespace std ;
const int N = 50 ;
int a[N] ;
int main(){
    string str ;
    getline(cin, str) ;
    int temp = 20 , index = 50 ;
    for(int i = 0 ; i < str.length() ; i ++)a[str[i] - 'a'] ++;
    for(int i = 0 ; i < str.length() ; i ++)if(a[str[i] - 'a'] < temp)temp = a[str[i] - 'a'] ;
    for(int i = 0 ; i < str.length() ; i ++ )if(a[str[i] - 'a'] > temp)cout<<str[i];
    return 0 ;
}
全部评论

相关推荐

在等offer的火锅...:我去履历这么好,都找不到工作吗?
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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