2014美团网笔试题目

上传人:博****1 文档编号:555022747 上传时间:2024-02-01 格式:DOC 页数:13 大小:50.50KB
返回 下载 相关 举报
2014美团网笔试题目_第1页
第1页 / 共13页
2014美团网笔试题目_第2页
第2页 / 共13页
2014美团网笔试题目_第3页
第3页 / 共13页
2014美团网笔试题目_第4页
第4页 / 共13页
2014美团网笔试题目_第5页
第5页 / 共13页
点击查看更多>>
资源描述

《2014美团网笔试题目》由会员分享,可在线阅读,更多相关《2014美团网笔试题目(13页珍藏版)》请在金锄头文库上搜索。

1、2014美团网笔试题目1、一堆硬币,一个机器人,如果是反的就翻正,如果是正的就抛掷一次,无穷多次后,求正反的比例解答:是不是题目不完整啊,我算的是3:12、一个汽车公司的产品,甲厂占40%,乙厂占60%,甲的次品率是1%,乙的次品率是2%,现在抽出一件汽车时次品,问是甲生产的可能性解答:典型的贝叶斯公式,p(甲|废品) = p(甲 & 废品) / p(废品) = (0.4 0.01) /(0.4 0.01 + 0.6 0.02) = 0.253、k链表翻转。给出一个链表和一个数k,比如链表123456,k=2,则翻转后214365,若k=3,翻转后321654,若k=4,翻转后432156,用

2、程序实现非递归可运行代码:#include#include#includetypedefstructnodestructnode*next;intdata;node;voidcreateList(node*head,intdata)node*pre,*cur,*new;pre=NULL;cur=*head;while(cur!=NULL)pre=cur;cur=cur-next;new=(node*)malloc(sizeof(node);new-data=data;new-next=cur;if(pre=NULL)*head=new;elsepre-next=new;voidprintLin

3、k(node*head)while(head-next!=NULL)printf(%d,head-data);head=head-next;printf(%dn,head-data);intlinkLen(node*head)intlen=0;while(head!=NULL)len+;head=head-next;returnlen;node*reverseK(node*head,intk)inti,len,time,now;len=linkLen(head);if(lenk)returnhead;elsetime=len/k;node*newhead,*prev,*next,*old,*t

4、ail;for(now=0,tail=NULL;nowtime;now+)old=head;for(i=0,prev=NULL;inext;head-next=prev;prev=head;head=next;if(now=0)newhead=prev;old-next=head;if(tail!=NULL)tail-next=prev;tail=old;if(head!=NULL)tail-next=head;returnnewhead;intmain(void)inti,n,k,data;node*head,*newhead;while(scanf(%d%d,&n,&k)!=EOF)for

5、(i=0,head=NULL;in;i+)scanf(%d,&data);createList(&head,data);printLink(head);newhead=reverseK(head,k);printLink(newhead);return0;5、利用两个stack模拟queue剑指offer上的原题,九度oj有专门的练习,这里贴一下我的ac代码:#include#include#includetypedefstructstackinttop;intseq100000;stack;/*入队操作*T=O(1)*/voidpushQueue(stack*s1,intdata)s1-se

6、qs1-top+=data;/*出队操作*T=O(n)*/voidpopQueue(stack*s1,stack*s2)if(s2-top0)printf(%dn,s2-seq-s2-top);elsewhile(s1-top0)s2-seqs2-top+=s1-seq-s1-top;if(s2-top0)printf(%dn,s2-seq-s2-top);elseprintf(-1n);intmain(void)intdata,n;stack*s1,*s2;charstr5;while(scanf(%d,&n)!=EOF)/初始化s1=(stack*)malloc(sizeof(stack)

7、;s2=(stack*)malloc(sizeof(stack);s1-top=s2-top=0;while(n-)scanf(%s,str);if(strcmp(str,PUSH)=0)/入队列scanf(%d,&data);pushQueue(s1,data);else/出队列popQueue(s1,s2);free(s1);free(s2);return0;6、一个m*n的矩阵,从左到右从上到下都是递增的,给一个数elem,求是否在矩阵中,给出思路和代码杨氏矩阵,简单题目:#include#include/*有序矩阵查找*T=O(n+n)*/voidfindKey(int*matrix,

8、intn,intm,intkey)introw,col;for(row=0,col=m-1;row=0;)if(matrixrowcol=key)printf(第%d行,第%d列n,row+1,col+1);break;elseif(matrixrowcolkey)col-=1;elserow+=1;printf(不存在!n);intmain(void)inti,j,key,n,m,*matrix;/构造矩阵scanf(%d%d,&n,&m);matrix=(int*)malloc(sizeof(int*)*n);for(i=0;in;i+)matrixi=(int*)malloc(sizeof(int)*m);for(i=0;in;i+)for(

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 资格认证/考试 > 自考

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号