中文字幕在线一区二区在线,久久久精品免费观看国产,无码日日模日日碰夜夜爽,天堂av在线最新版在线,日韩美精品无码一本二本三本,麻豆精品三级国产国语,精品无码AⅤ片,国产区在线观看视频

      C++面試題

      時(shí)間:2020-11-08 09:08:17 面試問(wèn)題 我要投稿

      C++面試題

      1、給定字符串 A 和 B,輸出 A 和 B 中的最大公共子串。
      比如 A="aocdfe" B="pmcdfa" 則輸出"cdf"
      */
      //Author: azhen
      #include<stdio.h>
      #include<stdlib.h>
      #include<string.h>
      char *commanstring(char shortstring[], char longstring[])
      {
      int i, j;
      char *substring=malloc(256);
      if(strstr(longstring, shortstring)!=NULL) //如果„„,那么返回 shortstring
      return shortstring;
      for(i=strlen(shortstring)-1;i>0; i--) //否則,開(kāi)始循環(huán)計(jì)算
      {
      for(j=0; j<=strlen(shortstring)-i; j++){
      memcpy(substring, &shortstring[j], i);
      substring[i]='\0';
      if(strstr(longstring, substring)!=NULL)
      return substring;
      }
      }
      return NULL;
      }
      main()
      {
      char *str1=malloc(256);
      char *str2=malloc(256);
      char *comman=NULL;
      gets(str1);
      gets(str2);
      if(strlen(str1)>strlen(str2)) //將短的字符串放前面
      comman=commanstring(str2, str1);
      else
      comman=commanstring(str1, str2);
      printf("the longest comman string is: %s\n", comman);
      }
      2、寫(xiě)一個(gè)函數(shù)比較兩個(gè)字符串 str1 和 str2 的.大小,若相等返回 0,若 str1 大于str2 返回 1,若 str1 小于 str2 返回-1
      int strcmp ( const char * src,const char * dst)
      {
      int ret = 0 ;
      while( ! (ret = *(unsigned char *)src - *(unsigned char *)dst) && *dst)
      {
      ++src;
      ++dst;
      }
      if ( ret < 0 )
      ret = -1 ;
      else if ( ret > 0 )
      ret = 1 ;
      return( ret );
      }
      3、求 1000!的未尾有幾個(gè) 0(用素?cái)?shù)相乘的方法來(lái)做,如 72=2*2*2*3*3);
      求出 1->1000 里,能被 5 整除的數(shù)的個(gè)數(shù) n1,能被 25 整除的數(shù)的個(gè)數(shù) n2,能被 125 整除的數(shù)的個(gè)數(shù) n3,
      能被 625 整除的數(shù)的個(gè)數(shù) n4.
      1000!末尾的零的個(gè)數(shù)=n1+n2+n3+n4;
      #include<stdio.h>
      #define NUM 1000
      int find5(int num){
      int ret=0;
      while(num%5==0){
      num/=5;
      ret++;
      }
      return ret;
      }
      int main(){
      int result=0;
      int i;
      for(i=5;i<=NUM;i+=5)
      {
      result+=find5(i);
      }
      printf(" the total zero number is %d\n",result);
      return 0;
      }
      4、有雙向循環(huán)鏈表結(jié)點(diǎn)定義為:
      struct node
      { int data;
      struct node *front,*next;
      };
      有兩個(gè)雙向循環(huán)鏈表 A,B,知道其頭指針為:pHeadA,pHeadB,請(qǐng)寫(xiě)一函數(shù)將兩鏈表中 data值相同的結(jié)點(diǎn)刪除
      BOOL DeteleNode(Node *pHeader, DataType Value)
      {
      if (pHeader == NULL) return;
      BOOL bRet = FALSE;
      Node *pNode = pHead;
      while (pNode != NULL)
      {
      if (pNode->data == Value)
      {
      if (pNode->front == NULL)
      {
      pHeader = pNode->next;
      pHeader->front = NULL;
      }
      else
      {
      if (pNode->next != NULL)
      {
      pNode->next->front = pNode->front;
      }
      pNode->front->next = pNode->next;
      }
      Node *pNextNode = pNode->next;
      delete pNode;
      pNode = pNextNode;
      bRet = TRUE;
      //不要 break 或 return, 刪除所有
      }
      else
      {
      pNode = pNode->next;
      }
      }
      return bRet;
      }
      void DE(Node *pHeadA, Node *pHeadB)
      {
      if (pHeadA == NULL || pHeadB == NULL)
      {
      return;
      }
      Node *pNode = pHeadA;
      while (pNode != NULL)
      {
      if (DeteleNode(pHeadB, pNode->data))
      {
      if (pNode->front == NULL)
      {
      pHeadA = pNode->next;
      pHeadA->front = NULL;
      }
      else
      {
      pNode->front->next = pNode->next;
      if (pNode->next != NULL)
      {
      pNode->next->front = pNode->front;
      }
      }
      Node *pNextNode = pNode->next;
      delete pNode;
      pNode = pNextNode;
      }
      else
      {
      pNode = pNode->next;
      }
      }
      }

      【C++面試題】相關(guān)文章:

      C/C++面試題目11-21

      精選C++面試題及答案10-03

      C,C++的幾個(gè)面試題小集11-24

      一個(gè)C/C++編程面試題11-22

      嵌入式C/C++面試題201611-12

      2016年c++經(jīng)典面試題及答案10-03

      華為C++筆試題11-23

      聯(lián)想C++筆試題11-23

      C++筆試實(shí)例分析11-22

      Sony C++筆試題11-22

      主站蜘蛛池模板: 镇远县| 久久久久久久久高潮无码| 亚洲欧美日韩在线中文一| 亚洲激情在线观看第三页| 国产精品无套粉嫩白浆在线| 玩弄人妻奶水无码AV在线| 99在线无码精品秘 入口九色| 日韩精品中文字幕 一区 | 久久精品这里就是精品| 国产高清一级毛片在线看| 日韩精品一区二区三区激情视频 | 国产精品久久久久亚洲| 柘城县| 伊宁县| 蜜桃一区二区免费视频观看| 日本区一区二在线免费观看| 91亚洲国产成人久久精品| 国产精品久久久一本精品| 屯留县| 肥西县| 芜湖县| 高清| 灵璧县| 西林县| 东莞市| 遵义市| 井冈山市| 商都县| 国产美女丝袜高潮白浆| 灵石县| 亚洲一区二区三区四区三级视频| 周宁县| 久久精品成人亚洲另类欧美| 正蓝旗| 好爽~又到高潮了毛片视频| 精品理论一区二区三区| 灵璧县| 亚洲无码性爱视频在线观看| 久久这里只有精品黄色| av在线免费播放网站| 成人永久福利在线观看不卡|