华为机试题目整理
来源:互联网 发布:平平无奇 古天乐 知乎 编辑:程序博客网 时间:2024/05/22 02:34
最近又到了招聘季了,现在也轮到我毕业了。针对华为的机试题目,我整理了一下自己写的一部分代码。</span>
代码参考别人和自己的理解写的,经过测试,可以运行。
如果有bug,或者更好的方法欢迎大家指出。
(一)
3. 通过键盘输入一串小写字母(a~z)组成的字符串。请编写一个字符串过滤程序,若字符串中出现多个相同的字符,将非首次出现的字符过滤掉。
比如字符串“abacacde”过滤结果为“abcde”。
要求实现函数:
void stringFilter(const char *pInputStr,long lInputLen, char *pOutputStr);
【输入】 pInputStr:输入字符串
lInputLen: 输入字符串长度
【输出】 pOutputStr:输出字符串,空间已经开辟好,与输入字符串等长;
<pre name="code" class="objc">#include<stdio.h>#include<string.h>#include<malloc.h>void stringFilter(const char *pInputStr, long lInputLen, char *pOutputStr);void main(){char *Instr, *Outstr;long int length = 0;Instr = (char *)malloc(sizeof(char));Outstr = (char *)malloc(sizeof(char));//printf("输入字符串的长度:");//scanf("%d", &length);printf("input the string:\n");scanf("%s", Instr);length = strlen(Instr);Outstr = (char *)malloc(length*sizeof(char));stringFilter(Instr, length, Outstr);printf("The output string is:%s\n", Outstr);}void stringFilter(const char *pInputStr, long lInputLen, char *pOutputStr){int index_i;int index_o=0;int label[26] = { 0 };if (pInputStr == NULL || pOutputStr == NULL){return;}for (index_i = 0; index_i < lInputLen; index_i++){if (label[pInputStr[index_i] - 'a'] == 0){label[pInputStr[index_i] - 'a']=1;pOutputStr[index_o] = pInputStr[index_i];index_o++;}}pOutputStr[index_o] = '\0';}
4.通过键盘输入一串小写字母(a~z)组成的字符串。请编写一个字符串压缩程序,将字符串中连续出席的重复字母进行压缩,并输出压缩后的字符串。
压缩规则:
1. 仅压缩连续重复出现的字符。比如字符串"abcbc"由于无连续重复字符,压缩后的字符串还是"abcbc".
2. 压缩字段的格式为"字符重复的次数+字符"。例如:字符串"xxxyyyyyyz"压缩后就成为"3x6yz"
要求实现函数:
void stringZip(const char*pInputStr, long lInputLen, char *pOutputStr);
【输入】 pInputStr: 输入字符串
lInputLen: 输入字符串长度
【输出】 pOutputStr: 输出字符串,空间已经开辟好,与输入字符串等长;
#include<stdio.h>#include<string.h>void stringZip(const char *pInputStr, long lInputLen, char *pOutputStr);void main(){char *Instr, *Outstr;int length;Instr = (char *)malloc(sizeof(char));Outstr = (char *)malloc(sizeof(char));printf("Input the String:\n");scanf("%s", Instr);length = strlen(Instr);stringZip(Instr, length, Outstr);printf("The Output String is:\n%s",Outstr);}void stringZip(const char *pInputStr, long lInputLen, char *pOutputStr){int index_i = 0;int index_o = 0;int f = 1;if (pInputStr == NULL || pOutputStr == NULL){return;}for (index_i = 0; index_i < lInputLen;){if (pInputStr[index_i] != pInputStr[index_i + 1]){pOutputStr[index_o++] = pInputStr[index_i++];}else{while (pInputStr[index_i] == pInputStr[index_i + f]){f++;}pOutputStr[index_o++] = f + '0';pOutputStr[index_o++] = pInputStr[index_i];index_i = index_i + f;}f = 1;}pOutputStr[index_o] = '\0';}
5.通过键盘输入100以内正整数的加、减运算式,请编写一个程序输出运算结果字符串。
输入字符串的格式为:“操作数1 运算符 操作数2”,“操作数”与“运算符”之间以一个空格隔开。
补充说明:
1. 操作数为正整数,不需要考虑计算结果溢出的情况。
2. 若输入算式格式错误,输出结果为“0”。
要求实现函数:
void arithmetic(const char*pInputStr, long lInputLen, char *pOutputStr);
【输入】 pInputStr: 输入字符串
lInputLen: 输入字符串长度
【输出】 pOutputStr: 输出字符串,空间已经开辟好,与输入字符串等长;
#include<stdio.h>#include<string.h>void arithmetic(const char *pInputStr, long lInputLen, char *pOutputStr);void main(){char *Instr, *Outstr;int length;Instr = (char *)malloc(sizeof(char));Outstr = (char *)malloc(sizeof(char));printf("Input the num:\n");gets(Instr);length = strlen(Instr);arithmetic(Instr, length, Outstr);printf("The result is :\n%s", Outstr);}void arithmetic(const char *pInputStr, long lInputLen, char *pOutputStr){int num1, num2;int out;int index_o = 0;char c;int cnt=0;if (pInputStr == NULL || pOutputStr == NULL){return;}for (int i = 0; i<lInputLen; ++i){if (pInputStr[i] == ' ')cnt++;}if (cnt != 2){pOutputStr[0] = '0';pOutputStr[1] = '\0';}if (sscanf(pInputStr, "%d %c %d", &num1, &c, &num2) != 3){pOutputStr[0] = '0';pOutputStr[1] = '\0';}if (c == '+'){out = num1 + num2;}else if (c == '-'){out = num1 - num2;}else{pOutputStr[0] = '0';pOutputStr[1] = '\0';}itoa(out, pOutputStr, 10);}
- 华为机试题目整理
- 华为2013年机试题目整理
- 2015华为机试题整理
- 华为机试题:图片整理
- 华为java机试题整理(二)
- 华为社招面试题(整理)
- 华为OJ试题整理
- 华为机试题目
- 华为机试题目
- 2014华为机试题目
- 华为2014机试题目
- 华为2014机试题目
- 华为机试题目 若干
- 华为2016机试题目
- 华为机试整理
- 华为2015机试题目汇总
- 华为2015校园招聘机试题目
- 华为机试题目---字符串替换
- js数组去重的三种常用方法总结
- Redis命令学习-SortedSet(有序集合)
- exploit - Immunity Debugger - PyCommands List
- [POI 2012]A Horrible Poem(字符串Hash)
- 插入与归并(25)
- 华为机试题目整理
- 使具有物理按键的手机能够显示Action Bar overflow
- JAVA List<> 合并去重
- python模拟Get请求保存网易歌曲的url
- CXF开发RESTful风格的Web Service
- 4103: [Thu Summer Camp 2015]异或运算
- 黑马程序员--NSArray,NSString,NSSet,NSDictionary,NSNumber,NSValue 及其可变(NSMutable..)
- 单一职责原则-和-开放-封闭原则-和-依赖倒转原则
- 数据源,动态代理