[华为机试真题][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;
}
相关文章推荐
- 黑马程序员——09_集合toArray的意义
- Leetcode#20 Valid Parentheses
- StringBuffer
- 开放《数据结构》专栏的代码
- Subsets
- AngularJS自定义表单验证
- 15-07-03 for ()语句-打印三角形
- 1032. 挖掘机技术哪家强(20)
- 常量指针与指针常量的区别
- 开放《图像处理与搜索》专栏的代码
- 黑马程序员——08_Arrays.asList泛型与打印时注
- Linux安装TTF/OTF字体
- nexus5 root教程
- Lightoj 1090 - Trailing Zeroes (II)
- 黑马程序员——07_Collections.reverseOrder()传入比较器时需注意
- Java环境变量classpath、path、JAVA_HOME 配置
- mina:ProtocolCodecFilter
- 题目1191:矩阵最大值
- typedef和define具体的详细区别
- [Objective-C] 011_数据持久化_NSKeyedArchiver