您的位置:首页 > 其它

[华为机试真题][2014]62.去除重复字符并排序

2015-07-05 22:47 447 查看
题目

描述:

去除重复字符并排序


运行时间限制:

无限制


内容限制:

无限制


输入:

字符串


输出:

去除重复字符并排序的字符串


样例输入:

aabcdefff


样例输出:

abcdef


代码

/*---------------------------------------
* 日期:2015-07-05
* 作者:SJF0115
* 题目:去除重复字符并排序* 来源:华为机试真题
-----------------------------------------*/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

string RemoveDuplicateAndSort(string str){
// 排序
sort(str.begin(),str.end());
string::iterator ite = str.begin();
string::iterator next;
// 删除重复
while(ite != str.end()){
next = ite+1;
if(*next == *ite){
str.erase(next);
}//if
else{
++ite;
}//else
}//while
return str;
}

int main(){
string str;
//freopen("C:\\Users\\Administrator\\Desktop\\acm.in","r",stdin);
while(getline(cin,str)){
cout<<RemoveDuplicateAndSort(str)<<endl;
}//while
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: