华为13年机试题
来源:互联网 发布:linux下安装make命令 编辑:程序博客网 时间:2024/05/21 19:39
一、题目描述(60分):通过键盘输入一串小写字母(a~z)组成的字符串。请编写一个字符串过滤程序,若字符串中出现多个相同的字符,将非首次出现的字符过滤掉。比如字符串“abacacde”过滤结果为“abcde”。要求实现函数:void stringFilter(const char *pInputStr, long lInputLen, char *pOutputStr);【输入】 pInputStr: 输入字符串 lInputLen: 输入字符串长度 【输出】 pOutputStr: 输出字符串,空间已经开辟好,与输入字符串等长; 【注意】只需要完成该函数功能算法,中间不需要有任何IO的输入输出示例 输入:“deefd” 输出:“def”输入:“afafafaf” 输出:“af”输入:“pppppppp” 输出:“p”main函数已经隐藏,这里保留给用户的测试入口,在这里测试你的实现函数,可以调用printf打印输出当前你可以使用其他方法测试,只要保证最终程序能正确执行即可,该函数实现可以任意修改,但是不要改变函数原型。一定要保证编译运行不受影响。 二、题目描述(40分):通过键盘输入一串小写字母(a~z)组成的字符串。请编写一个字符串压缩程序,将字符串中连续出席的重复字母进行压缩,并输出压缩后的字符串。压缩规则:1、仅压缩连续重复出现的字符。比如字符串"abcbc"由于无连续重复字符,压缩后的字符串还是"abcbc"。2、压缩字段的格式为"字符重复的次数+字符"。例如:字符串"xxxyyyyyyz"压缩后就成为"3x6yz"。要求实现函数: void stringZip(const char *pInputStr, long lInputLen, char *pOutputStr);【输入】 pInputStr: 输入字符串 lInputLen: 输入字符串长度【输出】 pOutputStr: 输出字符串,空间已经开辟好,与输入字符串等长;【注意】只需要完成该函数功能算法,中间不需要有任何IO的输入输出示例 输入:“cccddecc” 输出:“3c2de2c”输入:“adef” 输出:“adef”输入:“pppppppp” 输出:“8p
#include<iostream>
#include<set>using namespace std;void stringFilter(const char *pInputStr, long InputLen, char *pOutputStr){set<char>TestChar;pair<set<char>::iterator,bool>mark;int j = 0;for(int i = 0; i < InputLen;i++){mark = TestChar.insert(pInputStr[i]);if (mark.second ==true){pOutputStr[j++]=pInputStr[i];}}pOutputStr[j] = '\0';}void stringFilter2(const char *pInputStr, long InputLen, char *pOutputStr){bool mark[26] = {0};int j = 0;for(int i = 0;i < InputLen; i++){if (0 == mark[pInputStr[i] - 'a']){mark[pInputStr[i] - 'a'] = true;pOutputStr[j++] = pInputStr[i];}}pOutputStr[j]='\0';}void stringZip(const char *pInputStr, long InputLen, char *pOutputStr){int beg = 0,end = 0,j = 0,pos = 0;while (pInputStr[pos] != '\0'){beg = pos;end = pos+1;for (int i = pos; i < InputLen; i++){if (pInputStr[end] == pInputStr[i]){end++;}else{pos = end;break;}}if (end - beg == 1){pOutputStr[j++] = pInputStr[beg];}else{pOutputStr[j++]=(end-beg)+'0';pOutputStr[j++]=pInputStr[beg];}}pOutputStr[j]='\0';// if (end - beg == 1)// {// pOutputStr[j++] = pInputStr[beg];// }else// {// pOutputStr[j++]=end-beg+1-'0';// pOutputStr[j++]=pInputStr[beg];// }}int main(){char *p1 = "xxxyyyzz";char *p2 = new char[9];stringZip(p1,8,p2);while(*p2 !='\0'){cout <<*p2;p2++;}return 0;}
- 华为13年机试题
- 2012年 华为机试题
- 华为机试题2012年
- 华为2013年机试题
- 华为 2014 年 机试题一二
- 华为2013年机试题目整理
- 华为2014年机试题1
- 华为2014年机试题1
- 关于华为2014年机试题3
- 关于华为2014年机试题1
- 2015年 华为机试题(三)
- 华为2015年机试题(1)
- 华为机试题
- 2011 华为机试题
- 华为机试题
- 华为机试题
- 2013华为机试题
- 华为机试题
- RMI的分布式垃圾回收
- FieldInfo学习心得
- windows上如何查看占用某端口的进程
- git使用2_更新原有项目及将远程项目拖拽到本地
- 编程 感想
- 华为13年机试题
- Configuration类
- Java设计模式:代理模式
- Hibernate常用Annotation标签说明
- 线程同步方法:
- 腾讯在汉投资10亿 建设华中地区最大研发中心
- libsocket网络函数库
- 浅谈HTTP中Get与Post的区别
- Streams捕获进程