精品国产一级毛片大全,毛片一级在线,毛片免费观看的视频在线,午夜毛片福利

我要投稿 投訴建議

C++面試試題

時間:2023-03-26 13:30:42 面試試題 我要投稿

C++面試試題

  1、給定字符串 A 和 B,輸出 A 和 B 中的最大公共子串。

C++面試試題

  比如 A="aocdfe" B="pmcdfa" 則輸出"cdf"

  */

  //Author: azhen

  #include

  #include

  #include

  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--) //否則,開始循環(huán)計算

  {

  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、寫一個函數(shù)比較兩個字符串 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!的未尾有幾個 0(用素數(shù)相乘的方法來做,如 72=2*2*2*3*3);

  求出 1->1000 里,能被 5 整除的數(shù)的個數(shù) n1,能被 25 整除的數(shù)的個數(shù) n2,能被 125 整除的數(shù)的個數(shù) n3,

  能被 625 整除的數(shù)的個數(shù) n4.

  1000!末尾的零的個數(shù)=n1+n2+n3+n4;

  #include

  #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é)點定義為:

  struct node

  { int data;

  struct node *front,*next;

  };

  有兩個雙向循環(huán)鏈表 A,B,知道其頭指針為:pHeadA,pHeadB,請寫一函數(shù)將兩鏈表中 data值相同的結(jié)點刪除

  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;

  }

  }

http://www.ardmore-hotel.com/

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

C++面試試題08-04

C/C++面試試題09-26

C++程序員經(jīng)典面試筆試題09-26

聯(lián)想C++筆試題09-25

華為C++筆試題09-25

搜狗2017 C++筆試題09-25

C/C++ 程序設(shè)計員面試試題07-24

中興通訊C++/C筆試題09-26

C++程序員經(jīng)典筆試題09-26