【www.gbppp.com--题目解答】
2013年华为软件校园招聘编程测验
类别:软件C/C++语言
编程题(共3题)
注意:
1、请上机编写程序,按题目要求提交文件。[详见考试说明,点击进入考试说明]
2、本试题采用自动执行测试用例进行评分,测试用例不对考生公开
3、评卷通过在给定用例输入下,严格按照试题要求比较考生实现函数的输出与预设输出。两者相同则得分,不同则不得分
4、评卷人保证测试用例输入参数的合法性,考生不用考虑输入参数非法或异常的情况,题目中注明的例外
5、评卷人保证测试用例输入在被测函数正常合法情况下使用不会导致程序错误
6、被要求实现的函数如果包含返回参数,该返回参数涉及的空间分配和释放均在函数外完成,在被要求实现函数内部可以直接使用返回参数
7、如果考生函数异常导致程序崩溃或死循环,则自动评卷可能会被人为终止,剩余用例不被执行,无法得分
8、基于上述阅卷规则,请考生严格按照题目要求功能实现程序,尽量保证实现函数的稳健性,同时建议完成一道题并调试保证正确性后,再考虑并实现下一题目
1. 字符串处理
问题描述:
把一个字符串中的除大写字母、小写字母和数字字符之外的其他字符都去掉,输出新字符串。
要求实现函数:
void my_string(char* input, char* output)
【输入】 char* input,输入的字符串
【输出】 char* output, 输出的字符串
【返回】 无
示例
输入:input = “A*(BC&De+_fg/*”
输出:output = “ABCDefg”
输入:input = “aB+_9”
输出:output = “aB9”
2. 掷骰子游戏
问题描述:
在掷骰子游戏中,会根据所掷数字在地图中前进几步,前进完成后需要根据当前地图位置所示的障碍进行相应操作,其中障碍表示:
1) 9:无障碍
2) 1:停掷一轮,即下轮所掷数字无效;
3) 2:后退两步,如果已经到起点不再后退;
4) 3:奖励前进一步
如果在游戏过程中,已经走到地图终点,则游戏结束。根据输入的地图数组,和5个骰子数的数组,返回最终玩家前进了多少步。
要求实现函数:
void dice(int map_len, int* map, int* dice_val, int* output)
【输入】 int map_len,地图数组的长度
int* map,地图数组,值表示障碍
int* dice_val,5个骰子数的数组
【输出】 int *output,玩家共前进了多少步
【返回】 无
注:玩家是从起始位置开始,即地图数组的第一位,骰子数只能是1~6
示例
1) 输入:map_len = 15, map = {9,1,9,9,9,2,9,9,9,9,9,9,9,9,9},dice_val = {1,2,1,3,1},
返回:4
2) 输入:map_len = 16, map = {9,9,9,9,9,1,9,3,9,9,2,9,9,9,9,9},dice_val = {2,1,4,1,6},
返回:15
3. 表达式计算
问题描述:
在软件园开饭店的小明最近很郁闷,经常在进行账目核查时出错,每次的计算结果总是有偏差。小王知道后打算为小明解决这个问题,经过调查发现,问题出现在计算器上,当前的计算器计算方法大部分是:输入数据,输入运算符,再输入数据,立刻给出计算结果,然后不断循环。当计算结束时,如果出现偏差或者数据,无法回顾查看到底是哪一步出错,如果需要再次核查,还需要再全部输入一次,非常耽误时间。小王打算帮老板设计一种新的计算器,能够支持表达式的计算,由于是第一个版本,只需要支持整数的“+,-,*”和“( )”即可, 当然括号内的运算优先级高于括号外,“*”的优先级是高于“+,-”的。
注:输入的表达式字符串长度小于20。且表达式一定是合法的表达式。
要求实现函数:
void calculate(char* input, int* rel)
【输入】 char *input,待计算的表达式
【输出】 int* rel,计算结果
【返回】 无
示例
1) 输入:input = 5+2-10*2+5
输出:rel = -8
编程框架下载
1. 字符串处理
把一个字符串中的除大写字母、小写字母和数字字符之外的其他字符都去掉,输出新字符串。 要求实现函数:
void my_string(char* input, char* output)
【输入】 char* input,输入的字符串
【输出】 char* output, 输出的字符串
【返回】 无
示例
输入:input = “A*(BC&De+_fg/*”
输出:output = “ABCDefg”
输入:input = “aB+_9”
输出:output = “aB9”
#include <stdio.h>
void my_string(char* input, char* output);
int main(void)
{
char input[] = "A*(BC&De+_fg/*";
char output[14];
my_string(input, output);
char input1[] = "aB+_9";
char output1[6];
my_string(input1, output1);
my_string(input2, output2);
return 0;
}
void my_string(char* input, char* output)
{
int i,j=0;
for(i=0; input[i]!='\0'; i++)
{
if( ( input[i]>='0')&&(input[i]<='9') || (input[i]>='a')&&(input[i]<='z')\
|| (input[i]>='A')&&(input[i]<='Z') )
{
output[j] = input[i];
j++;【华为2013校园招聘】
}
}
output[j] = '\0';
printf("the output is %s\n",output);
}
2. 掷骰子游戏
在掷骰子游戏中,会根据所掷数字在地图中前进几步,前进完成后需要根据当前地图位置所示的障碍进行相应操作,其中障碍表示:
1) 9:无障碍
2) 1:停掷一轮,即下轮所掷数字无效;
3) 2:后退两步,如果已经到起点不再后退;
4) 3:奖励前进一步
如果在游戏过程中,已经走到地图终点,则游戏结束。根据输入的地图数组,和5个骰子数的数组,返回最终玩家前进了多少步。
要求实现函数:
void dice(int map_len, int* map, int* dice_val, int* output)
【输入】 int map_len,地图数组的长度
int* map,地图数组,值表示障碍
int* dice_val,5个骰子数的数组
【输出】 int *output,玩家共前进了多少步
【返回】 无
注:玩家是从起始位置开始,即地图数组的第一位,骰子数只能是1~6
示例
1) 输入:map_len = 15, map = {9,1,9,9,9,2,9,9,9,9,9,9,9,9,9},dice_val = {1,2,1,3,1},
返回:4
2) 输入:map_len = 16, map = {9,9,9,9,9,1,9,3,9,9,2,9,9,9,9,9},dice_val = {2,1,4,1,6},
返回:15
#include <stdio.h>
void dice(int map_len, int* map, int* dice_val, int* output);
int main(void)
{
int map_len = 15, map[] = {9,1,9,9,9,2,9,9,9,9,9,9,9,9,9}, dice_val[] = {1,2,1,3,1};//4
int a=0 , * output=&a;
dice(map_len, map, dice_val, output);
int map_len1 = 16, map1[] = {9,9,9,9,9,1,9,3,9,9,2,9,9,9,9,9}, dice_val1[] = {2,1,4,1,6};//15
int a1=0 , * output1=&a1;
dice(map_len1, map1, dice_val1, output1);
return 0;
}
//方法2
void dice(int map_len, int* map, int* dice_val, int* output)
{
int step=0, i;
for(i=0; i<5; i++)
{
step = step + dice_val[i];
if(step>=map_len - 1)
{
*output = map_len - 1;
step = map_len - 1;
break;
}
else if(map[step] == 1)
i++;
else if(map[step] == 2)
{
if(step>1)
step = step - 2;
else
step = 0;
}
else if(map[step] == 3)
step++;
}
*output = step;
printf("the output is %d\n",*output);
}
3题目描述:
输入一个字符串,将其中大写字母转换为对应小写字母之后的第五个字母,
若原始大写字母为V~Z, 则转换为对应小写字母的值减21。
其他字符不变,输出转换后的字符串。
例如,对于字母A,则转换为小写字母f;若形参是字母W,则转换为小写字母b
要求实现函数:
void TransferString(const char * pInputStr, long lInputLen, char * pOutputStr);
【输入】 pInputStr: 输入字符串
lInputLen: 输入字符串长度【华为2013校园招聘】
【输出】 pOutputStr: 输出字符串,空间已经开辟好,与输入字符串等长;
【注意】只需要完成该函数功能算法,中间不需要有任何IO的输入输出
示例
输入:“Axs3mWss”
输出:“fxs3mbss”
/*
#include <stdio.h>
#include <stdlib.h>
void TransferString(const char * pInputStr, long lInputLen, char * pOutputStr);
int main(void)
{
char * pInputStr = "Axs3mWss";
long lInputLen = 8;
char * pOutputStr;
pOutputStr = (char *)malloc(8+1);
TransferString(pInputStr, lInputLen, pOutputStr);
printf("%s\n",pOutputStr);
return 0;
}
*/
void TransferString(const char * pInputStr, long lInputLen, char * pOutputStr)
{
for(int i = 0; i < lInputLen; i++)
{
if( (pInputStr[i] >='A') && (pInputStr[i] <='U'))
pOutputStr[i] = pInputStr[i] + 32 + 5;
else if( (pInputStr[i] >='V') && (pInputStr[i] <='Z') )
pOutputStr[i] = pInputStr[i] + 32 - 21;
else
pOutputStr[i] = pInputStr[i];
}
pOutputStr[i] = '\0';
}
4. 将一个字符串的元音字母复制到另一个字符串,并排序(30分)
问题描述:有一字符串,里面可能包含英文字母(大写、小写)、数字、特殊字符,现在需要实现一函数,将此字符串中的元音字母挑选出来,存入另一个字符串中,并对字符串中的字母进行从小到大的排序(小写的元音字母在前,大写的元音字母在后,依次有序)。
说明:1、 元音字母是a,e,i,o,u,A,E,I,O,U。
2、 筛选出来的元音字母,不需要剔重;最终输出的字符串,小写元音字母排在前面,大写元音
字母排在后面,依次有序。
要求实现函数:void sortVowel (char* input, char* output);
【输入】 char* input,表示输入的字符串
【输出】 char* output,排好序之后的元音字符串。
【返回】 无
示例 : 输入:char *input = “Abort!May Be Some Errors In Out System.“
输出:char *output =“aeeeooAEIO “
#include <stdio.h>
void sortVowel (char* input, char* output);
int main(void)
{
//char *input = "Abort!May Be Some Errors In Out System.";//不能改变字符串字面量,所以不能是声明指针指向的字符串应该是字符数组才可以。
char input[] = "Abort!May Be Some Errors In Out System.";//"AEOIUBBBvvvaeiuo";
char output[500] ;
sortVowel (input, output);
return 0;
}
/*
void sortVowel (char* input, char* output)
{
char temp[50];
for(int i = 0, j = 0; input[i] !='\0'; i++)
{
if( (input[i] == 'a') || (input[i] == 'e') || (input[i] == 'i') || (input[i] == 'o') || (input[i] == 'u') \ ||(input[i] == 'A') || (input[i] == 'E') || (input[i] == 'I') || (input[i] == 'O') || (input[i] == 'U') )
temp[j++] = input[i];
}
temp[j] = input[i];
int k = 0;
for(j = 0; temp[j] !='\0'; j++)//a
{
if(temp[j] == 'a')
output[k++] = temp[j];
}
for(j = 0; temp[j] !='\0'; j++)//e
{
if(temp[j] == 'e')
output[k++] = temp[j];
}
for(j = 0; temp[j] !='\0'; j++)//i
{
if(temp[j] == 'i')
output[k++] = temp[j];
}
for(j = 0; temp[j] !='\0'; j++)//o
{
if(temp[j] == 'o')
output[k++] = temp[j];
}
for(j = 0; temp[j] !='\0'; j++)//u
{
if(temp[j] == 'u')
output[k++] = temp[j];
}
for(j = 0; temp[j] !='\0'; j++)//A
{
if(temp[j] == 'A')
output[k++] = temp[j];
}
for(j = 0; temp[j] !='\0'; j++)//E
{
if(temp[j] == 'E')
output[k++] = temp[j];【华为2013校园招聘】
}
for(j = 0; temp[j] !='\0'; j++)//I
{
if(temp[j] == 'I')
output[k++] = temp[j];
}
for(j = 0; temp[j] !='\0'; j++)//O
{
if(temp[j] == 'O')
output[k++] = temp[j];
}
for(j = 0; temp[j] !='\0'; j++)//U
{
if(temp[j] == 'U')
output[k++] = temp[j];
}
output[k] = '\0';
printf("%s\n",output);
}
*/
void sortVowel (char* input, char* output)
{
int i=0,j=0,k=0;
int numlong;
char temp;
while(* (input+i)!='\0')
{
if(*(input+i)=='a'||*(input+i)=='e'||*(input+i)=='i'|| *(input+i)=='o'||*(input+i)=='u'||*(input+i)=='A'|| *(input+i)=='E'||*(input+i)=='I'||*(input+i)=='O'|| *(input+i)=='U')
*(output+j++)=*(input+i);
i++;
}
output[j] = '\0';
numlong=j;
for(i=1;i<j;i++)
{
for(k=0;k<j-i;k++)
{
华为公司校园招聘个人简历
简历编号
1492933 姓 名 XXX 移动电话 183XXXXXXXX
求职意向
1.软件开发工程师 2.研究工程师
是否愿意接受应聘职位的调整 期望工作地点 服从分配 是 是否愿意接受期望工作地点的调整
应聘职位
我保证所填写表格的每一项内容及所提供的个人信息(包括简历、证书,及其他在应聘过程中提供的个人材料)的真实性,并愿意接受公司或其委托的合法机构对以上所有信息调查确认。如有作假行为,愿接受公司的相关处理以及取消本人的录用资格。
申请人签名:
申请日期:
2016校招机试题
第一题
输入一串用空格隔开的数字串,对于数字串的奇数位按升序排序,偶数位按降序排序 示例输入:4 6 2 3 7 8 1
处理过程:
奇数位:4268升序排序结果:2468
偶数位:6371 降序排序结果:7631
结果输出:2 7 4 6 6 3 8 1
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void sort(char input[], int n, char output[]);
void main()
{
char input1[]="4 6 2 3 6 7 8 1";
char output1[16];
int m=15;
sort(input1,m,output1);
for(int i=0;i<m;i++)
printf("%c ",output1[i]);
printf("\n");
}
void sort(char input[],int n,char output[])
{
int i,j,t1,t2,t=0;
int *b=(int *)malloc(sizeof(int)*n);
int *c=(int *)malloc(sizeof(int)*n);
b[0]=input[0]-'0';
for(i=4,t1=1;i<n;i+=4,t1++)
{
for(j=t1-1;((input[i]-'0')<b[j])&&(j>=0);j--)
{
b[j+1]=b[j];
}
b[j+1]=input[i]-'0';
}
c[0]=input[2]-'0';
for(i=6,t2=1;i<n;i+=4,t2++)
{
for(j=t2-1;((input[i]-'0')>c[j])&&(j>=0);j--)
{
c[j+1]=c[j];
}
c[j+1]=input[i]-'0';
}
for(i=0,j=0;i<n;i+=4,j++)
{
output[i]=b[j]+'0';
output[i+1]=' ';
output[i+2]=c[j]+'0';
output[i+3]=' ';
}
}
2.精灵王子爱好冒险,在一次探险历程中,他进入了一个神秘的山洞。在洞穴深处,精灵王子不小心触动了洞穴内暗藏的机关,整个洞穴将很快塌陷,精灵王子必须尽快逃离洞穴。精灵王子的跑步速度为17m/s,以这样的速度可能是无法逃出洞穴的。庆幸的是精灵王子拥有闪烁法术,可在1s内移动60m,不过每次使用闪烁法术都会消耗法值10点。精灵王子的魔法值恢复的速度为4点/s,只能在原地休息状态时才能恢复。
现在已知精灵王子的魔法初值M,他所在洞穴中的位置与洞穴出口之间的距离S,距离洞穴塌陷的时间T. 你的任务是写一个程序帮助精灵王子计算如何在最短时间内逃离洞穴。 若能逃出,输出“Yes”,并输出逃出所用的最短时间;若不能逃出,则输出”No“,同时输出精灵王子在剩下的时间内能走的最远距离。注意字母大小写。注意精灵王子跑步,闪烁或休息活动均以秒(s)为单位。且每次活动的持续时间为整数秒。距离的单位为米(m)。
注:M,S,T均是大于等于0的整数。由输入保证取值合法性,考生不用检查。 提醒:
如果输入的S为0,则说明本身已经在出口,输出应为:Yes 0
如果输入的T为0(且S不为0),则说明已经没有时间了,输出应为:No 0
输入格式:
M
S
T
输出格式:
Yes 逃出洞穴所用时间
或
No在洞穴塌陷前能逃跑的最远距离
10
#include<stdio.h>
void main()
{
int M,S,T;
int de1=0,de2=0;
int start=T;
scanf("%d %d %d",&M,&S,&T);
if(S==0)
printf("Yes 0\n");
else
{
} } if(T==0) printf("No 0\n"); else { while(T) { T--; if(M>=10) { M-=10; de1+=60; } else { M+=4; } de2+=17; if(de2<de1) de2=de1; if(de2>S) { printf("Yes %d\n",start-T); break; } else { printf("No %d\n",de2); break; } } }
2015校招机试题
第一题(60分):
按要求分解字符串,输入两个数M,N;M代表输入的M串字符串,N代表输出的每串字符串的位数,不够补0。例如:输入2,8, “abc” ,“123456789”,则输出为“abc00000”,“12345678“,”90000000”
#include<stdio.h>
#include<string.h>
void main()
{
int m,n,i,j,p=0;
char str[1024];
int a[10];
scanf("%d%d",&m,&n);
printf("please input %d string:\n",m);
for(i=0;i<m;i++)
{
scanf("%s",&str[p]);
a[i]=strlen(str+p);
p=p+a[i];
}
p=0;
for(i=0;i<m;i++)
{
if(a[i]<n)
{
for(j=p;j<p+a[i];j++)
printf("%c",str[j]);
for(j=a[i];j<n;j++)
printf("0");
printf("\n");
}
else if(a[i]==n)
{
for(j=p;j<p+a[i];j++)
printf("%c",str[j]);
printf("\n");
}
else
{
for(j=p;j<n+p;j++)
printf("%c",str[j]);
printf("\n");
for(j=n+p;j<a[i]+p;j++)
printf("%c",str[j]);
for(j=0;j<(2*n-a[i]);j++)
printf("0");
printf("\n");
}
p=p+a[i];
}
}
第一题:拼音转数字
输入是一个只包含拼音的字符串,请输出对应的数字序列。转换关系如下: 描述: 拼音 yi er san si wu liu qi ba jiu
阿拉伯数字 1 2 3 4 5 6 7 8 9
输入字符只包含小写字母,所有字符都可以正好匹配
运行时间限制:无限制
内存限制: 无限制
输入: 一行字符串,长度小于1000
输出: 一行字符(数字)串 样例输入: yiersansi
样例输出: 1234
#include<stdio.h>
#include<string.h>
void main()
{
int i,j;
char str[1000];
char ch;
scanf("%s",str);
int len=strlen(str);
for(i=0;i<len;)
{
switch (str[i])
{
case 'y':
printf("1"); i=i+2;
break;
case 'e':
printf("2"); i=i+2;
break;
case 's':
if(str[i+1]=='a') {
printf("3"); i=i+3; }
else
{
printf("4"); i=i+2; }
break;
case 'w':
printf("5"); i=i+2;
break;
case 'l':
printf("6"); i=i+3;
break;
case 'q':
printf("7"); i=i+2;
华为机器校园招聘须知
尊敬的深圳职业技术学院领导:
您好,很荣幸与贵校的合作!
为确保本次校园招聘工作的顺利进行,有以下事宜需提前沟通并切实准备、宣传到位:
一、本次校园招聘的时间段:
1、 2014年3月4日(周二下午14:00-18:00)
二、招聘程序:
2、 校企双方合作沟通――校园招聘宣讲会——考试——阅卷——公布面试人员名单——面试——
查学籍档案及处分记录——公布录用人员名单——录用人员座谈会——与校对口专业科主任、老师座谈――结束。
3、 在以上过程中会参观学校的教学设备、实验设备、实习工厂、学生宿舍等作为我司对贵校的招
聘考核指标之一。
三、面试资料准备:
1、 《应聘人员登记表》(正反面打印在一张纸上);
2、 《考核表》(正反面打印在一张纸上);
3、 个人简历(或学校推荐表)1份;
4、 成绩单原件1份(须需盖有学校教务处公章);可报到前提供;
5、 个人学历证明原件一份(必须盖有学校公章);
6、 身份证复印件1份(或户口薄复印件)。
注:请提前督促学生按以上顺序装订好面试材料(如面试材料不完整,将失去面试资格);
7、 具体事宜沟通、联络老师一名,确保招聘过程中各种招聘相关信息的准确、及时的传达;
8、 其他协助人员2名(学生干部即可)。
四、报名条件:
1、 年龄要求:1996年12月1日以前出生(报到时满18周岁)
本文来源:http://www.gbppp.com/jy/457065/
推荐访问:华为校园招聘官网 华为公司校园招聘