• [华为]删除字符串中出现次数最少的字符


    实现删除字符串中出现次数最少的字符,若多个字符出现次数一样,则都删除。输出删除这些单词后的字符串,字符串中其它字符保持原来的顺序。

    输入描述:字符串只包含小写英文字母, 不考虑非法输入,输入的字符串长度小于等于20个字节。
    输出描述:删除字符串中出现次数最少的字符后的字符串。
    输入例子abcdd

    输出例子:dd

     1 #include <iostream>
     2 #include <string>
     3 using namespace std;
     4 int main()
     5 {    
     6     int i, m,min;    
     7     int a[26];    
     8     string str,temp;    
     9     while (cin >> str)    
    10     {        
    11         for (int i = 0; i < 26; i++)            
    12             a[i] = 0;                //初始化数组都为0
    13         m = str.size();        
    14         
    15         for (i = 0; i<m; i++)            
    16             a[str[i]-'a']++;         //计数 
    17         
    18         min = a[str[0]-'a'];        
    19         
    20         for (i = 0; i<m; i++)        
    21             
    22             if (a[str[i] - 'a'] <= min)           
    23                 min = a[str[i]-'a'];        
    24         
    25         for (i = 0; i < m; i++)        
    26             if (a[str[i] - 'a'] > min)           
    27                 cout << str[i];         
    28         cout << endl;    
    29     }       
    30     return 0;
    31 }
  • 相关阅读:
    QT之sqlite连接
    QT之QCustomPlot(二)
    QT之QCustomPlot(一)
    Qt第三方库QCustomPlot——QCustomPlot解读
    C++ 头文件系列(sstream)
    C++ 头文件系列(streambuf)
    C++ 头文件系列(iostream)
    C++ 头文件系列(ostream)
    C++ 头文件系列(istream)
    C++ 头文件系列(ios)
  • 原文地址:https://www.cnblogs.com/hellochennan/p/6668752.html
Copyright © 2020-2023  润新知