2015提前批 60分
通过键盘输入一串小写字母(a~z)组成的字符串。请编写一个字符串过滤程序,若字符串中出现多个相同的字符,将非首次出现的字符过滤掉,然后按字母表顺序输出。 比如字符串“abfcacde”输出结果为“abcdef”。
先对字符串排序,然后再过滤相同的,输出。
#include<iostream>
#include<string>
using namespace std;
void main(){
string s;
cin >> s;
int len, i, j;
char temp;
len = s.size();
for (i = 0; i < len - 1; i++){
for (j = 0; j < len - 1 - i; j++){
if (s[j]>s[j + 1]){
temp = s[j];
s[j] = s[j + 1];
s[j + 1] = temp;
}
}
}
i = 0;
cout << s[0];
while (i != len){
i++;
if (s[i] != s[i-1])
cout << s[i];
}
cout << endl;
system("pause");
}