2014年7月华为校招机试真题2
来源:互联网 发布:动态桌面主题下载软件 编辑:程序博客网 时间:2024/04/28 08:27
去除重复字符并排序
运行时间限制:无限制
内容限制: 无限制
输入: 字符串
输出: 去除重复字符并排序的字符串
样例输入: aabcdefff
样例输出: abcdef
#include<stdio.h>#include<iostream>#include <iterator>#include<map>using namespace std;void stringFilter(const char *pInputStr, char *pOutputStr) { int length=strlen(pInputStr);int j(0);map<char,int> m;for(int i=0; i<length; i++) m[pInputStr[i]]++;for( map<char,int>::iterator iter= m.begin();iter!=m.end();iter++) pOutputStr[j++] = (*iter).first;pOutputStr[j]='\0';}void stringFilter1(const char *pInputStr, char *pOutputStr) {if (pInputStr == NULL || pOutputStr == NULL ){return; }int length = strlen(pInputStr);if (length < 255){int a[256]={0};//必须初始化不然内存存的是各种各样的数值const char* pstr = pInputStr; char* pResult = pOutputStr; while ( *pstr != '\0'){++a[*pstr - 'a'];if (a[*pstr - 'a'] > 1){pstr++;}else {*pResult++ = *pstr++;}}*pResult = '\0';}else{cout << "Please input the 1-255 zifuchaun " << endl;return; }}int main(){char a[256];strcpy(a,"aabcdefff");//bbabacacdechar b[256]=""; //stringFilter(a,b);//将字符排序后输出,不符合有些情况stringFilter1(a,b);cout << a << endl;cout << "字符过滤后:\n";cout << b << endl;return 0;}
测试结果:
}
0 0
- 2014年7月华为校招机试真题2
- 2014年7月华为校招机试真题1
- 2014年7月华为校招机试真题3
- 2014年7月华为校招机试真题4
- [C/C++]2014年7月华为校招机试真题(一)
- [C/C++]2014年7月华为校招机试真题(二)
- [C/C++]2014年7月华为校招机试真题(一)
- [C/C++]2014年7月华为校招机试真题(一)
- 2014年7月华为校招机试第一题答案另解--Java版本
- 2013年9月华为上机题
- 2014 8月华为软件类上机笔试
- 2014 8月华为软件类上机笔试题目解答
- 2014校园招聘之一(8月华为机试题)
- 2013年9月华为机试题目
- 2013年9月华为机试题目
- 2005年11月华为在南邮的招聘笔试题
- 2005年11月华为在南邮的招聘笔试题
- 2013年5月华为实习生招聘之机试练习题
- linux常用命令(22):find 命令的参数详解
- Rtaudio在VS下的使用
- php 相对路径中 ./ 与../的区别
- 腾讯面试
- C# 画图控件CHART 自定义坐标轴刻度标签
- 2014年7月华为校招机试真题2
- HTTP Status 404 - There is no Action mapped for namespace [/] and action name [login!welcome] associ
- UC/OS II事件管理(1)
- POJ 1064(二分)
- Centos7 安装kilo-3 controller(keystone)
- 每日一“结”(1)
- 【offer感悟】本科生如何才能进入BAT等一流的互联网公司(软件工程师等研发方向)?
- iOS-CGContextRef画各种图形例子
- C# 将一个对象转换为指定类型