[华为]删除字符串中出现次数最少的字符
实现删除字符串中出现次数最少的字符,若多个字符出现次数一样,则都删除。输出删除这些单词后的字符串,字符串中其它字符保持原来的顺序。输入描述:字符串只包含小写英文字母, 不考虑非法输入,输入的字符串长度小于等于20个字节。
输出描述:删除字符串中出现次数最少的字符后的字符串。
输入例子abcdd
输出例子:dd
#include <iostream>
#include <string>
using namespace std;
int main()
{
int i, m,min;
int a;
string str,temp;
while (cin >> str)
{
for (int i = 0; i < 26; i++)
a = 0; //初始化数组都为0
m = str.size();
for (i = 0; i<m; i++)
a-'a']++; //计数
min = a-'a'];
for (i = 0; i<m; i++)
if (a - 'a'] <= min)
min = a-'a'];
for (i = 0; i < m; i++)
if (a - 'a'] > min)
cout << str;
cout << endl;
}
return 0;
}
页:
[1]