华为机试南京面试题.docx

上传人:b****3 文档编号:27551922 上传时间:2023-07-02 格式:DOCX 页数:13 大小:18.58KB
下载 相关 举报
华为机试南京面试题.docx_第1页
第1页 / 共13页
华为机试南京面试题.docx_第2页
第2页 / 共13页
华为机试南京面试题.docx_第3页
第3页 / 共13页
华为机试南京面试题.docx_第4页
第4页 / 共13页
华为机试南京面试题.docx_第5页
第5页 / 共13页
点击查看更多>>
下载资源
资源描述

华为机试南京面试题.docx

《华为机试南京面试题.docx》由会员分享,可在线阅读,更多相关《华为机试南京面试题.docx(13页珍藏版)》请在冰豆网上搜索。

华为机试南京面试题.docx

华为机试南京面试题

求一串字符串中出现次数最多的单词

 

南京

同学都陆续到华为参加了机试,题目整体难度不大,基本上都是考字符串相关的题目。

这里就分享一套2012年华为南京机试C++或者C的编程题目。

2012年华为南京机试第一题整数化成字符串

给定一个整数(有可能是负数),将整数变成字符串。

函数已经声明好类似voidchange(intnumber,chars[])的形式。

可以自己写用例测试。

2012年华为南京机试第二题单链表逆序

给定一个已经定义好的单链表,将单链表中的数字逆序。

输入为head指针,返回的也是一个head指针。

函数声明为voidsor(Node**head)的形式。

2012年华为南京机试第三题字符串最大回文子串

给定一个字符串,寻找它的一个最大子串,该子串是回文。

例如给定用例字符串”gabcdcbaef”,那么最大回文字串是”abcdcba”。

函数声明为voidhuiwen(charinput[],intlen,charoutput[])。

一天几个考场的题目有相同的也有不同的,基本上难度都不大。

要求做前两题就可以了,有能力的可以做第三题并且计入总分。

有同学做完当场就看到是100分,也有0分的,至于怎么计分的不太清楚。

希望七叶草提供的2012年华为南京机试编程题对你有帮助!

武汉

题目:

有一个数组a[N]如a[10]={0,1,2,3,4,5,6,7,8,9}每隔两个数删除一个数,如0,1,2(删除),3,4,5(删除),6,7,8(删除),9,到数组尾部回到数组头部继续删除,要求编写一个函数实现实现上述操作,返回最后一个数的数组下标。

函数接口:

intgetLast(intiLen)

参数:

数组初始元素个数iLen

01

#include

02

#include

03

 

04

typedef struct node*List;

05

typedef struct node*PNode;

06

 

07

typedef struct node

08

{

09

    int data;

10

    struct node*next;

11

}Node;

12

 

13

int getLast(int iLen)

14

{

15

    int i;

16

    ListL;

17

    PNodetempNode,current;

18

    L=(List)malloc(sizeof(Node));

19

    L->next=NULL;

20

    current=L;

21

    for (i=0;i

22

    {

23

        tempNode=(PNode)malloc(sizeof(Node));

24

        tempNode->data=i;

25

        current->next=tempNode;

26

        current=tempNode;

27

    }

28

    current->next=L->next;

29

    current=L;

30

    while (iLen>1)

31

    {

32

        current=current->next->next;

33

        tempNode=current->next;

34

        current->next=tempNode->next;

35

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

36

        free(tempNode);

37

        iLen--;

38

    }

39

    return current->data;

40

}

41

 

42

int main()

43

{

44

    printf("lastof20is%d",getLast(20));

45

    return 0;

46

}

编程题(共2题,第一题40分,第二题60分,共100分。

请上机编写轨范,按题目要求提交文件。

[详见考试申明]

本试题采用自动测试用例进行评分,测试用例过错考生公开,凡不满足提交要求导致不能运行或用例不经由过程,不予评分)。

1.删除字符串中所有给定的子串(40分)

问题描述:

 

在给定字符串中查找所有特定子串并删除,若是没有找到响应子串,则不作任何操作。

要求实现函数:

 

intdelete_sub_str(constchar*str,constchar*sub_str,char*result_str)

【输入】str:

输入的被操作字符串

        sub_str:

需要查找并删除的特定子字符串

【输出】result_str:

在str字符串中删除所有sub_str子字符串后的终局

【返回】删除的子字符串的个数

I、  子串匹配只考虑最左匹配情况,即只需要从左到右进行字串匹配的情况。

比如:

在字符串"abababab"中,采用最左匹配子串"aba",可以匹配2个"aba"字串。

若是

匹配出从左到右位置2起头的"aba",则不是最左匹配,且只能匹配出1个"aba"字串。

II、 输入字符串不会跨越100Bytes,请不用考虑超长字符串的情况。

示例 

输入:

str="abcde123abcd123"

sub_str="123"

输出:

result_str="abcdeabcd"

返回:

2

输入:

str="abcde123abcd123"

sub_str="1234"

输出:

result_str="abcde123abcd123"

返回:

0

2.高精度整数加法(60分)

问题描述:

 

在计较机中,由于措置器位宽限制,只能措置有限精度的十进制整数加减法,比如在32位宽措置器计较机中,

参与运算的操作数和终局必须在-231~231-1之间。

若是需要进行更年夜规模的十进制整数加法,需要使用特殊

的体式格局实现,比如使用字符串保存操作数和终局,采纳逐位运算的体式格局。

如下:

9876543210+1234567890=?

让字符串num1="9876543210",字符串num2="1234567890",终局保存在字符串result="11111111100"。

-9876543210+(-1234567890)=?

让字符串num1="-9876543210",字符串num2="-1234567890",终局保存在字符串result="-11111111100"。

要求编程实现上述高精度的十进制加法。

要求实现函数:

 

voidadd(constchar*num1,constchar*num2,char*result)

【输入】num1:

字符串形式操作数1,若是操作数为负,则num1[0]为符号位-

num2:

字符串形式操作数2,若是操作数为负,则num2[0]为符号位-

【输出】result:

保存加法计较终局字符串,若是终局为负,则result[0]为符号位。

I、  当输入为正数时,+不会出今朝输入字符串中;当输入为负数时,-会出今朝输入字符串中,且必然在输入字符串最左边位置;

II、 输入字符串所有位均代表有效数字,即不存在由0起头的输入字符串,比如"0012","-0012"不会呈现;

III、      要求输出字符串所有位均为有效数字,终局为正或0时+不出今朝输出字符串,终局为负时输出字符串最左边位置为-。

示例 

输入:

num1="580"

num2="-50"

输出:

result="530"

输入:

num1="580"

num2="-600"

输出:

result="-20"

#include

usingnamespacestd;

intdeletestr(constchar*str,constchar*sub_str,char*result)

 constchar*p=str;

 constchar*p1=str;

 constchar*q=sub_str;

 intk=0;

 while(*p!

=/0)

 if((*p==*q)&&*q!

=/0)

  p++;

  q++;

 constchar*ptr=p;

  if(*p==/0)

     *result=/0;

 elseif(*q==/0)

    q=sub_str;

    k++;

    p1=p;

 elseif(*p!

=/0&&*q!

=/0)

    *result++=*p1;

     p1++;

     p=p1;

     q=sub_str;

if(*q!

=/0)

       p=p1;

       while(*p!

=/0)

       *result++=*p++;

       *result=/0;

  } 

voidalg(constchar*str1,constchar*str2,char*result) 

 constchar*p=str1;

 constchar*q=str2;

 intm=0,n=0;

 while(*p!

=/0)

 p++;

 m++;

 while(*q!

=/0)

 q++;

 n++;

 p=p-1;

 q=q-1; 

 if((*str1!

=-&&*str2!

=-)||(*str1==-&&*str2==-))

    if(*str1==-)

     m--;

     n--;

    *result=0;

    while(m>0&&n>0)

       if(((*result+*p+*q)-3*0)>=10)

          *result=0+((*result+*p+*q)-3*0)%10;

          result++;

          *result=1;

          p--;

          q--;

        else

            *result=0+((*result+*p+*q)-3*0);

              if((m==n)&&m!

=1)

              result++;

              *result=0;

              elseif(m!

=n)

              result++;

              *result=0;

            p--;

            q--;

            m--;

            n--;

    if(m>0)

       while(m>0)

        if((*result+*p-2*0)>=10)

              *result=0+(*result+*p-2*0)%10;

              result++;

              *result=1;

         else

             *result=0+(*result+*p-2*0);

             if(m!

=1)

              result++;

              *result=0;

        p--;

        m--;   

      elseif(n>0)

       while(n>0)

        if((*result+*q-2*0)>=10)

              *result=0+(*result+*q-2*0)%10;

              result++;

              *result=1;

         else

             *result=0+(*result+*q-2*0);

              if(n!

=1)

                result++;

                *result=0;

        q--;  

        n--; 

   if(*str1!

=-)    

     result++;

     *result=/0;

   else

    result++;

    *result=-; 

    result++;

    *result=/0;   

else

  intk1=0;

  intk2=0;

  constchar*p1;

  constchar*p2;

  constchar*ptr1;

  constchar*ptr2;

  if(*str1==-)

     k1=m-1;

     k2=n;

     p1=p;

     p2=q;

     ptr1=str1+1;

     ptr2=str2;

  elseif(*str2==-)

    k1=n-1;

    k2=m;

    p1=q;

    p2=p;

    ptr1=str2+1;

    ptr2=str1;

  inttemp=0;//long

  constchar*temptr;//pointeroflong

  inttemp1=0; 

  constchar*temptr1; 

  if(k1>k2)

    temp=k1;

    temp1=k2;

    temptr=p1;

    temptr1=p2;

  elseif(k1

     temp=k2;

     temp1=k1;

     temptr=p2;

     temptr1=p1;

  else

    while(*ptr1==*ptr2)

      ++ptr1;

      ++ptr2;

    if((*ptr1-*ptr2)>0)

       temp=k1;

       temp1=k2;

       temptr=p1;

       temptr1=p2;

     else

       temp=k2;

       temp1=k1;

       temptr=p2;

       temptr1=p1;

  *result=0;

 while(temp1>0)

      if((0-*result+*temptr-*temptr1)>=0)

           *result=2*0-*result+*temptr-*temptr1;

           result++;

           *result=0;

 temptr--;

           temptr1--;

           temp1--;

           temp--;

       else

         *result=-*result+*temptr-*temptr1+1+9;

         result++;

         *result=1;

         temp1--;  

         temp--;

         temptr--;

         temptr1--;

if(temp>0)

  while(temp>0)

      if((-*result+*temptr)>=0)

         *result=0+(-*result+*temptr);

         if(temp!

=1)

          result++;

          *result=0;

         temp--;

         temptr--;                   

      else 

       *result=1+9-0+(-*result+*temptr);

       result++;

       *result=1;

       temp--;

       temptr--;

   if(*result==0)

      if(*temptr==-)

       *result=-;

       ++result;

       *result=/0;

      else

       *result=/0;

   else

      if(*temptr==-)

       ++result;

       *result=-;

       ++result;

       *result=/0;

       else

        ++result;

       *result=/0;

else

   if(*result==0)

     --result;              

     while(*result==0)

        --result;

        ++result;

      if(*temptr==-)

       *result=-;

       ++result;

       *result=/0;

      else

       *result=/0;

   else

      if(*temptr==-)

       ++result;

       *result=-;

       ++result;

       *result=/0;

       else

        ++result;

       *result=/0;

 }

intmain()

 char*str="abcdabbabcacbaabcdabcababc";

 char*sub_str="ab";

 charresult[100];

 char*str1="-1462";

 char*str2="473";

 charre[10];

 alg(str1,str2,re);

 deletestr(str,sub_str,result);

 cout<

 system("pause");

 return0;

 }

(注:

可编辑下载,若有不当之处,请指正,谢谢!

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 求职职场 > 笔试

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1