




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
201*校园招聘研发类笔试题PPTV_201*校内聘请研发类笔试题
PPTV_201*校内聘请研发类笔试题
扩展阅读:201*华为校内聘请软件研发笔试题
1、删除子串,只要是原串中有相同的子串就删掉,不管有多少个,返回子串个数。#include#include#include#include
intdelete_sub_str(constchar*str,constchar*sub_str,char*result){
assert(str!=NULLconstchar*p,*q;char*t,*temp;p=str;
q=sub_str;t=result;
intn,count=0;n=strlen(q);
temp=(char*)malloc(n+1);memset(temp,0x00,n+1);while(*p){
memcpy(temp,p,n);
if(strcmp(temp,q)==0){
count++;
memset(temp,0x00,n+1);p=p+n;}else{
*t=*p;p++;t++;
memset(temp,0x00,n+1);}}
free(temp);returncount;}
voidmain(){
chars={‘\\0’};
intnum=delete_sub_str(“123abc12de234fg1hi34j123k”,”123”,s);printf(“Thenumberofsub_stris%d\\r\\n”,num);printf(“Theresultstringis%s\\r\\n”,s);}
2、约瑟夫环是一个数学的应用问题:已知n个人(以编号1,2,3...n分别表示)围坐在一张圆桌四周。从编号为k的人开头报数,数到m的那个人出列;他的下一个人又从1开头报数,数到m的那个人又出列;依此规律重复下去,直到圆桌四周的人全部出列。#include#includetypedefstructNode{
intnum;
structNode*next;}LinkList;
LinkList*creat(intn){
LinkList*p,*q,*head;inti=1;
p=(LinkList*)malloc(sizeof(LinkList));p->num=i;head=p;
for(i=2;inum=i;p->next=q;p=q;}
p->next=head;/*使链表尾指向链表头形成循环链表*/returnhead;}
voidfun(LinkList*L,intm){
inti;
LinkList*p,*s,*q;p=L;
printf("出列挨次为:");while(p->next!=p){
for(i=1;inext;}
printf("%5d",p->num);s=p;
q->next=p->next;p=p->next;free(s);}
printf("%5d\\n",p->num);}
intmain(){
LinkList*L;intn,m;n=9;m=5;
L=creat(n);fun(L,m);return0;}
3、比较一个数组的元素是否为回文数组#include#includeinthuiwen(charstr){
inti,len,k=1;len=strlen(str);
for(i=0;i#include#include
intarray_pare(intlen1,intarray1,intlen2,intarray2){
intcount=0;
for(;len1>=0len1--,len2--){
if(array1!=array2){
count++;}}
returncount;}
intmain(){
intresult=0;
intarray1={1,3,5};intlen1=3;
intarray2={77,12,1,3,5};intlen2=5;
result=array_pare(len1,array1,len2,array2);///result=array_pare(len1,array1,len2,array2);不能这样
//函数形参中永久只是传得首地址,不能传数组切记切记!!!!!!printf("theresultis%d",result);}
5、随机数按计数输出
问题描述:
输入一个由随机数组成的数列(数列中每个数均是大于0的整数,长度已知),和初始计数值m。从数列首位置开头计数,计数到m后,将数列该位置数值替换计数值m,并将数列该位置数值出列,然后从下一位置从新开头计数,直到数列全部数值出列为止。假如计数到达数列尾段,则返回数列首位置连续计数。请编程实现上述计数过程,同时输出数值出列的挨次
比如:输入的随机数列为:3,1,2,4,初始计数值m=7,从数列首位置开头计数(数值3所在位置)第一轮计数出列数字为2,计数值更新m=2,出列后数列为3,1,4,从数值4所在位置从新开头计数其次轮计数出列数字为3,计数值更新m=3,出列后数列为1,4,从数值1所在位置开头计数第三轮计数出列数字为1,计数值更新m=1,出列后数列为4,从数值4所在位置开头计数最终一轮计数出列数字为4,计数过程完成。输出数值出列挨次为:2,3,1,4。
要求实现函数:
voidarray_iterate(intlen,intinput_array,intm,intoutput_array)intlen:输入数列的长度;intintput_array:输入的初始数列intm:初始计数值
intoutput_array:输出的数值出列挨次无示例
输入:intinput_array={3,1,2,4},intlen=4,m=7输出:output_array={2,3,1,4}
////////////循环链表实现//////////////////////#include#include#includetypedefstructNode{
intnum;
structNode*next;}node;
node*creat(intlen,intinput_array){
node*h,*s,*p;inti;
h=(node*)malloc(sizeof(node));h->num=input_array;p=h;
for(i=1;inum=input_array;p->next=s;p=s;}
p->next=h;
return(h);}
voidarray_iterate(intlen,intinput_array,intm){
node*q,*p,*s;inti=0,j=0,k;
intoutput_array;
p=creat(len,input_array);while(p->next!=p){
for(i=1;inext;}
m=p->num;
//printf("%5d",m);output_array=m;s=p;
q->next=p->next;p=p->next;free(s);s=NULL;}
m=p->num;
//printf("%5d\\n",m);output_array=p->num;k=j;
for(j=0;j
#include#include#include#include#defineLENGTH13
intverifyMsisdn(char*inMsisdn){
char*pchar=NULL;
assert(inMsisdn!=NULL);
if(LENGTH==strlen(inMsisdn)){
if(("8"==*inMsisdn)
for(;len1>0len1--,len2--){
if(array1!=array2){
count++;}}
returncount;}
intmain(){
intresult=0;
intarray1={1,3,5};intlen1=3;
intarray2={77,12,1,3,5,7};intlen2=6;
result=array_pare(len1,array1,len2,array2);
///result=array_pare(len1,array1,len2,array2);不能这样
//函数形参中永久只是传得首地址,不能传数组切记切记!!!!!!printf("theresultis%d",result);}
8、简洁四则运算
问题描述:输入一个只包含个位数字的简洁四则运算表达式字符串,计算该表达式的值注:1、表达式只含+,-,*,/四则运算符,不含括号
2、表达式数值只包含个位整数(0-9),且不会消失0作为除数的状况3、要考虑加减乘除按通常四则运算规定的计算优先级
4、除法用整数除法,即仅保留除法运算结果的整数部分。比如8/3=2。输入表达式保证无0作为除数状况发生
5、输入字符串肯定是符合题意合法的表达式,其中只包括数字字符和四则运算符字符,除此之外不含其它任何字符,不会消失计算溢出状况要求实现函数:
intcalculate(intlen,char*expStr)intlen:字符串长度;char*expStr:表达式字符串;无
计算结果
示例
1)输入:char*expStr=“1+4*5-8/3”函数返回:19
2)输入:char*expStr=“8/3*3”函数返回:6#include#includeusingnamespacestd;
intcalculate(intlen,char*expStr){
struct{
charopdata;inttop;
}opstack;//定义操作符栈opstack.top=-1;
inti=0;//遍历字符串的下标intt=0;//当前后缀表达式的长度charch=expStr;while(ch!="\\0"){switch(ch){case"+":case"-":while(opstack.top!=-1){expStr=opstack.opdata;opstack.top--;t++;
}opstack.top++;
opstack.opdata=ch;
break;
case"*":
case"/":
while(opstack.top!=-1opstack.top--;
t++;
}}}opstack.top++;
opstack.opdata=ch;break;
default:
expStr=ch;t++;break;
i++;
ch=expStr;
while(opstack.top!=-1)//将栈中全部的剩余的运算符出栈{
expStr=opstack.opdata;}
expStr="\\0";struct
{opstack.top--;t++;
intnumeric;inttop;
}data;
data.top=-1;i=0;
ch=expStr;
while(ch!="\\0"){if(ch>="0"data.top--;
data.numeric=tmp;
printf("cannotbezeroofthedivide\\n");exit(1);
i++;
ch=expStr;
}}voidmain(){
charexpStr="9/3*5";returndata.numeric;
printf("%s\\n",expStr);}
9、选秀节目打分,分为专家评委和大众评委,score数组里面存储每个评委打的分数,judge_type里存储与score数组对应的评委类别,judge_type==1,表示专家评委,judge_type==2,表示大众评委,n表示评委总数。打分规章如下:专家评委和大众评委的分数先分别取一个平均分(平均分取整),然后,总分=专家评委平均分*0.6+大众评委*0.4,总分取整。假如没有大众评委,则总分=专家评委平均分,总分取整。函数最终返回选手得分。函数接口intcal_score(intscore,intjudge_type,intn)#include#include#include#include#defineN5
intresult=calculate(strlen(expStr),expStr);printf("%d\\n",result);
intcal_score(intscore,intjudge_type,intn){
intexpert=0;intdazhong=0;intzongfen=0;inti;
intnumber=0;
for(i=0;i例如:input={3,6,1,9,7}output={3,7,9,6,1};input={3,6,1,9,7,8}output={1,6,8,9,7,3}#include#include#include
voidsort(intinput,intn,intoutput){
inti,j;intk=1;inttemp;intmed;
for(i=0;iintmain(){
inta={3,6,1,9,7,8};intb={0};
for(inti=0;i=50且{
system_task=task;pp=i;j++;}
count=j;}
elseif(task
for(i=0;i//把两数组倒置
for(i=0;i{
length++;
}printf(“Thelengthofstringis%d\\n”,length);return0;
}14、使用C语言实现字符串中子字符串的替换
描述:编写一个字符串替换函数,如函数名为StrReplace(char*strSrc,char*strFind,char*strReplace),strSrc为原字符串,strFind是待替换的字符串,strReplace为替换字符串。举个直观的例子吧,如:“ABCDEFGHIJKLMNOPQRSTUVWXYZ”这个字符串,把其中的“RST”替换为“ggg”这个字符串,结果就变成了:ABCDEFGHIJKLMNOPQgggUVWXYZ答案一:
#include#include
voidStrReplace(char*strSrc,char*strFind,char*strReplace);#defineM100;voidmain()
{chars="ABCDEFGHIJKLMNOPQRSTUVWXYZ";chars1="RST";chars2="ggg";
StrReplace(s,s1,s2);printf("%s\\n",s);}
voidStrReplace(char*strSrc,char*strFind,char*strReplace){
inti=0;intj;
intn=strlen(strSrc);intk=strlen(strFind);for(i=0;ifor(;*s;s++){
for(p=s1;*pp++);if(*p)*s=*(p-s1+s2);}}
intmain(){
chars;//s是原字符串chars1,s2;//s1是要替换的//s2是替换字符串puts("Pleaseinputthestringfors:");scanf("%s",s);
puts("Pleaseinputthestringfors1:");scanf("%s",s1);
puts("Pleaseinputthestringfors2:");scanf("%s",s2);
StrReplace(s,s1,s2);
puts("Thestringofsafterdisplaceis:");printf("%s\\n",s);return0;}
答案三:
#include#include#include#defineM100
voidStrReplace(char*strSrc,char*strFind,char*strReplace);intmain(){
chars="ABCDEFGHIJKLMNOPQRSTUVWXYZ";chars1="RST";chars2="gggg";StrReplace(s,s1,s2);printf("%s\\n",s);return0;}
voidStrReplace(char*strSrc,char*strFind,char*strReplace){
while(*strSrc!="\\0"){
if(*strSrc==*strFind){
if(strncmp(strSrc,strFind,strlen(strFind))==0){
inti=strlen(strFind);intj=strlen(strReplace);printf("i=%d,j=%d\\n",i,j);char*q=strSrc+i;printf("*q=%s\\n",q);
while((*strSrc++=*strReplace++)!="\\0");printf("strSrc-1=%s\\n",strSrc-1);printf("*q=%s\\n",q);
while((*strSrc++=*q++)!="\\0");}else{
strSrc++;}}else{
strSrc++;}}}
15、编写一个程序实现功能:将字符串”ComputerSecience”赋给一个字符数组,然后从第一个字母开头间隔的输出该串,用指针完成。答案:
#include#includeintmain(){
charstr=”ComputerScience”;intflag=1;char*p=str;while(*p)
{if(flag){
printf(“%c”,*p);}
flag=(flag+1)%2;p++;}
printf(“\\n”);return0;}16、(和第14题一样)使用C语言实现字符串中子字符串的替换
描述:编写一个字符串替换函数,如函数名为StrReplace(char*strSrc,char*strFind,char*strReplace),strSrc为原字符串,strFind是待替换的字符串,strReplace为替换字符串。举个直观的例子吧,如:“ABCDEFGHIJKLMNOPQRSTUVWXYZ”这个字符串,把其中的“RST”替换为“ggg”这个字符串,结果就变成了:ABCDEFGHIJKLMNOPQgggUVWXYZ答案一:
#include#include
voidStrReplace(char*strSrc,char*strFind,char*strReplace);#defineM100;voidmain()
{chars="ABCDEFGHIJKLMNOPQRSTUVWXYZ";chars1="RST";chars2="ggg";
StrReplace(s,s1,s2);printf("%s\\n",s);}
voidStrReplace(char*strSrc,char*strFind,char*strReplace){
inti=0;intj;
intn=strlen(strSrc);intk=strlen(strFind);for(i=0;ireturn0;}
答案三:
#include#include#include#defineM100
voidStrReplace(char*strSrc,char*strFind,char*strReplace);intmain(){
chars="ABCDEFGHIJKLMNOPQRSTUVWXYZ";chars1="RST";chars2="gggg";
StrReplace(s,s1,s2);printf("%s\\n",s);
return0;}
voidStrReplace(char*strSrc,char*strFind,char*strReplace){
while(*strSrc!="\\0"){
if(*strSrc==*strFind){
if(strncmp(strSrc,strFind,strlen(strFind))==0){
inti=strlen(strFind);intj=strlen(strReplace);printf("i=%d,j=%d\\n",i,j);char*q=strSrc+i;printf("*q=%s\\n",q);
while((*strSrc++=*strReplace++)!="\\0");printf("strSrc-1=%s\\n",strSrc-1);printf("*q=%s\\n",q);
while((*strSrc++=*q++)!="\\0");}else{
strSrc++;}}else{
strSrc++;}}}
17、编写一个程序实现功能:将两个字符串合并为一个字符串并且输出,用指针实现。
charstr1={“Hello”},str2={“World”};答案:
#include
intmain(){
charstr1={“Hello”},str2={“World”};char*p=str1,*q=str2;
while(*p)p++;while(*q){
*p=*q;p++;q++;}
*p=‘\\0’;
printf(“%s\\n”,str1);
return0;}
18、算分数的问题,去掉一个最高分一个最低分,求平均分
1.#include
2.floatavescore(floatscore,intn)3.{
4.floatmin=0;5.floatmax=0;6.intminindex=0;7.intmaxindex=0;8.floatsum=0;9.min=score;
10.for(inti=0;i30.voidmain()31.{
32.floatscore={70,80,90,98,87,86};33.floatlastscore;
34.lastscore=avescore(score,6);
35.printf("thelastscoreis:%5.2f\\n",lastscore);36.37.}运行结果:
thelastscoreis:85.75
19、对一个数组,将数组中偶数从大到小排序,奇数从小到大排序,奇数和偶数交叉着放且输出数组第一位放奇数若奇数和偶数不等长,则把剩下的直接放到数组中。
思路:先进行奇偶推断,得到奇数和偶数数组。然后对两数组排序,进行长度推断,最终组织数据。
#include
1.#include2.
3.voidjiou(inta,intn)4.{
5.int*p1;6.int*p2;7.inti,j;8.intk=0;9.intkk=0;
10.intcount1=0;11.intcount2=0;12.inttemp;13.inttemp2;14.intm=0;
15.p1=(int*)malloc(sizeof(int)*n);16.p2=(int*)malloc(sizeof(int)*n);17.for(i=0;i6.47.48.
for(i=0;i87.for(i=0;iif(*(inID+i)"9")return2;}
if(*(inID+17)"9")if(*(inID+17)!="x")return3;
chartemp1={0};chartemp2={0};chartemp3={0};
memcpy(temp1,inID+6,4);intyear=atoi(temp1);
if(year2100)return4;
memcpy(temp2,inID+10,2);intmon=atoi(temp2);if(mon12)return5;
memcpy(temp3,inID+12,2);intday=atoi(temp3);
if(1==mon){
if(day31)return6;}
if(2==mon)//能被4整除且不能被100整除或能被400整除的年份,闰年的2月份为29天,非闰年的2月份为28天。{
if(((year%4==0)}else{
if(day28)return6;}}
if(3==mon){
if(day31)return6;}
if(4==mon){if(day30)return6;}
if(5==mon){
if(day31)return6;}
if(6==mon){
if(day30)return6;}
if(7==mon){
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论