返回首页

美团网校园招聘笔试试题

时间:2015-03-15 22:39来源:电脑教程学习网 www.etwiki.cn 编辑:admin

1、一堆硬币,一个机器人,如果是反的就翻正,如果是正的就抛掷一次,无穷多次后,求正反的比例

解答:3:1

2、一个汽车公司的产品,甲厂占40%,乙厂占60%,甲的次品率是1%,乙的次品率是2%,现在抽出一件汽车时次品,问是甲生产的可能性

解答:典型的贝叶斯公式,p(甲|废品) = p(甲 && 废品) / p(废品) = (0.4 × 0.01) /(0.4 × 0.01 + 0.6 × 0.02) = 0.25

3、k链表翻转。给出一个链表和一个数k,比如链表1→2→3→4→5→6,k=2,则翻转后2→1→4→3→6→5,若k=3,翻转后3→2→1→6→5→4,若k=4,翻转后4→3→2→1→5→6,用程序实现。

非递归可运行代码:
#include

#include

#include

typedef struct node {

struct node *next;

int data;

} node;

void createList(node **head, int data)

{

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;

else

pre->next = new;

}

void printLink(node *head)

{

while (head->next != NULL) {

printf("%d ", head->data);

head = head->next;

}

printf("%d\n", head->data);

}

int linkLen(node *head)

{

int len = 0;

while (head != NULL) {

len ++;

head = head->next;

}

return len;

}

node* reverseK(node *head, int k)

{

int i, len, time, now;

len = linkLen(head);

if (len < k) {

return head;

} else {

time = len / k;

}

node *newhead, *prev, *next, *old, *tail;

for (now = 0, tail = NULL; now < time; now ++) {

old = head;

for (i = 0, prev = NULL; i < k; i ++) {

next = head->next;

head->next = prev;

prev = head;

head = next;

}

if (now == 0) {

newhead = prev;

}

old->next = head;

if (tail != NULL) {

tail->next = prev;

}

顶一下
(4)
100%
踩一下
(0)
0%
标签(Tag):美团网 校园招聘笔试试题
------分隔线----------------------------
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
验证码:点击我更换图片
推荐内容