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

来源:互联网 发布:java ocr验证码识别 编辑:程序博客网 时间:2024/06/16 13:19

题目

描述:

去除重复字符并排序

运行时间限制:

无限制

内容限制:

无限制

输入:

字符串

输出:

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

样例输入:

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;}
0 0
原创粉丝点击