题解 | #删除字符串中出现次数最少的字符#
删除字符串中出现次数最少的字符
http://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9
感觉大家思路都差不多怎么我的时间就多那么多呢
#include <string>
#include <memory.h>
using namespace std;
int main()
{
string str;
int minValue;
int a[26];
while(cin >> str) {
if (str.length() <= 0) {
cout << "" << endl;;
continue;
}
memset(a, 0, sizeof(a));
for(int i = 0; i < str.length(); i++) {
a[int(str[i] - 'a')] += 1;
}
minValue = a[int(str[0] - 'a')];
//最小出现的次数
for(int i = 0; i < sizeof(a)/sizeof(a[0]); i++) {
if (a[i] > 0 && a[i] <= minValue) {
minValue = a[i];
}
}
//输出
for (int i = 0; i < str.length(); i++) {
if (a[int(str[i]-'a')] > minValue)
cout << str[i];
}
cout << endl;
}
}