目前本站已有 十几万 份求职资料啦!


IT公司笔试常考的算法题

12-17 15:54:36 来源:http://www.qz26.com 笔试题目   阅读:8182
导读:int change(char *str) {int i,j=strlen(str)-1;for(i=j; j>=0; j--) {if(str!='*') {i--;} else if(str[j]!='*') {str = str[j];str[j] = '*';i--;}}return i+1;}17、20xx年11月15日华为软件研发笔试题。实现一单链表的逆转。#include "stdafx.h"typedef char eleType; // 定义链表中的数据类型typedef struct listnode { // 定义单链表结构eleType data;struct listnode *next;}node;node *create(int n) { // 创建单链表,n为节点个数node *p = (node *)malloc(sizeof(node));node *head = p; head->data
IT公司笔试常考的算法题,标签:银行笔试题目,企业笔试题目,http://www.qz26.com

  int change(char *str) {

  int i,j=strlen(str)-1;

  for(i=j; j>=0; j--) {

  if(str!='*') {

  i--;

  } else if(str[j]!='*') {

  str = str[j];

  str[j] = '*';

  i--;

  }

  }

  return i+1;

  }

  17、20xx年11月15日华为软件研发笔试题。实现一单链表的逆转。

  #include "stdafx.h"

  typedef char eleType; // 定义链表中的数据类型

  typedef struct listnode { // 定义单链表结构

  eleType data;

  struct listnode *next;

  }node;

  node *create(int n) { // 创建单链表,n为节点个数

  node *p = (node *)malloc(sizeof(node));

  node *head = p; head->data = 'A';

  for(int i='B'; i<'A'+n; i++) {

  p = (p->next = (node *)malloc(sizeof(node)));

  p->data = i;

  p->next = NULL;

  }

  return head;

  }

  void print(node *head) { // 按链表顺序输出链表中元素

  for(; head; head = head->next)

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

  printf("\n");

  }

  node *reverse(node *head, node *pre) { // 逆转单链表函数。这是笔试时需要写的最主要函数

  node *p=head->next;

  head->next = pre;

  if(p) return reverse(p, head);

  else return head;

  }

  int main(int argc, char* argv[]) {

  node *head = create(6);

  print(head);

  head = reverse(head, NULL);

  print(head);

  }

  18、编码实现字符串转整型的函数(实现函数atoi的功能),据说是神州数码笔试题。如将字符串 ”+123”123, ”-0123”-123, “123CS45”123, “123.45CS”123, “CS123.45”0

  #include "stdafx.h"

  int str2int(const char *str) { // 字符串转整型函数

  int i=0, sign=1, value = 0;

  if(str==NULL) return NULL; // 空串直接返回 NULL

  if(str[0]=='-' || str[0]=='+') { // 判断是否存在符号位

  i = 1;

  sign = (str[0]=='-' ? -1 : 1);

  }

  for(; str>='0' && str<='9'; i++) // 如果是数字,则继续转换

  value = value * 10 + (str - '0');

  return sign * value;

  }

  int main(int argc, char *argv[]) {

  char *str = "-123.45CS67";

  int val = str2int(str);

  printf("str=%s\tval=%d\n", str, val);

  }

  19、歌德巴赫猜想。任何一个偶数都可以分解为两个素数之和。(其实这是个C二级考试的模拟试题)

  #include "stdafx.h"

  #include "math.h"

  int main(int argc, char* argv[]) {

  int Even=78, Prime1, Prime2, Tmp1, Tmp2;

  for(Prime1=3; Prime1<=Even/2; Prime1+=2) {

  for(Tmp1=2,Tmp2=sqrt(float(Prime1)); Tmp1<=Tmp2 && Prime1%Tmp1 != 0; Tmp1++);

  if(Tmp1<=Tmp2) continue;

  Prime2 = Even-Prime1;

  for(Tmp1=2,Tmp2=sqrt(float(Prime2)); Tmp1<=Tmp2 && Prime2%Tmp1 != 0; Tmp1++);

  if(Tmp1<=Tmp2) continue;

  printf("%d=%d+%d\n", Even, Prime1, Prime2);

  }

  }

上一页  [1] [2] [3] [4] [5] [6] [7] [8]  下一页


Tag:笔试题目银行笔试题目,企业笔试题目求职笔试面试 - 笔试题目
【字号: 】 【打印】 【关闭
最新更新
推荐热门
联系我们 | 网站地图 | 财务资料 | 范文大全 | 求职简历 | 财会考试 | 成功励志
Copyright 二六求职资料网 All Right Reserved.
1 2 3 4 5 6 7 8 9 10