去掉字符串中重复的字符并排序
来源:互联网 发布:供应商管理商业数据库 编辑:程序博客网 时间:2024/05/21 10:54
第二题:去除重复字符并排序
运行时间限制:无限制
内容限制: 无限制
输入: 字符串
输出: 去除重复字符并排序的字符串
样例输入: aabcdefff
样例输出: abcdef
- 方法1
#define _CRT_SECURE_NO_DEPRECATE#include <iostream>#include <string>#include <algorithm>using namespace std;/** * 去掉字符串中重复的字符并排序 */int main(){ string input; while (cin>>input) { int count = 0; // 统计有多少个空格 for (int i = 0; i < input.size(); i++) { for (int j = i+1; j < input.size(); j++) { if (input[i] == ' ') break; if (input[i] == input[j]) { input[j] = ' '; count++; } } } int newsize = input.size() - count; string str(newsize,'0'); //创建一个长为newsize,用‘0’填充的字符串 int j = 0; for (int i = 0; i < input.size(); i++) { if (input[i] != ' ') { str[j] = input[i]; j++; } } sort(str.begin(), str.end()); cout << str<<endl; }}
还是人家写的好http://blog.csdn.net/hackbuteer1/article/details/39253767
- 方法2
#include <iostream>#include <vector>#include <algorithm>using namespace std;int main(){ string input; cin >> input; sort(input.begin(),input.end()); input.erase(unique(input.begin(),input.end()),input.end()); cout << input <<endl; return 0;}
0 0
- 去掉字符串中重复的字符并排序
- 去掉字符串中重复的字符
- 去掉字符串中重复的字符
- javascript去掉字符串中重复的字符
- javascript去掉字符串中重复的字符
- 去掉字符串中重复字符
- 去掉字符串中重复的字符 --- 华为笔试题
- [转]去掉字符串中重复的字符 --- 华为笔试题
- 统计字符串中重复的字符个数并输出
- 去掉字符串中重复的子字符串
- 去掉重复字符串并排序 例如12342343454565678789->123456789
- 黑马程序员_去掉字符串中连续重复字符函数
- Cracking coding interview(1.3)去掉字符串中重复字符
- 去掉排序数组中重复的数字
- C#去掉数组中重复的字符串
- C#去掉数组中重复的字符串
- C#去掉数组中重复的字符串
- 华为2012.09.03浙大机试题 去掉字符串中的重复字符,字符串中重复字符的压缩,根据输入计算字符串结果
- Project Euler:Problem 33 Digit cancelling fractions
- 6个月新GRE复习计划分享
- SAT阅读考试需要养成好习惯
- MAC环境变量
- 把txt转换成pdf的广泛使用方法
- 去掉字符串中重复的字符并排序
- Android自定义控件(状态提示图表)
- MFC单文档下为视图类添加按钮及其响应事件
- 用自定义keystore调试微信分享app
- 页面置换算法
- Unity5.0与Android交互
- 重新编译php支持freetype
- Unsupported major.minor version 51.0
- android微信支付开发