<dfn id="w48us"></dfn><ul id="w48us"></ul>
  • <ul id="w48us"></ul>
  • <del id="w48us"></del>
    <ul id="w48us"></ul>
  • C++面試題

    時間:2020-11-08 09:08:17 面試問題 我要投稿

    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--) //否則,開始循環計算
    {
    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、寫一個函數比較兩個字符串 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(用素數相乘的方法來做,如 72=2*2*2*3*3);
    求出 1->1000 里,能被 5 整除的數的個數 n1,能被 25 整除的數的個數 n2,能被 125 整除的數的個數 n3,
    能被 625 整除的數的個數 n4.
    1000!末尾的零的個數=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、有雙向循環鏈表結點定義為:
    struct node
    { int data;
    struct node *front,*next;
    };
    有兩個雙向循環鏈表 A,B,知道其頭指針為:pHeadA,pHeadB,請寫一函數將兩鏈表中 data值相同的結點刪除
    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++面試題】相關文章:

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

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

    C,C++的幾個面試題小集11-24

    一個C/C++編程面試題11-22

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

    2016年c++經典面試題及答案10-03

    華為C++筆試題11-23

    聯想C++筆試題11-23

    C++筆試實例分析11-22

    Sony C++筆試題11-22

    主站蜘蛛池模板: www.亚洲精品| 国产精品久久久久久| 国产精品看高国产精品不卡| 精品人妻少妇一区二区三区在线| 亚洲午夜国产精品无码| 久久成人精品视频| 亚洲Av永久无码精品三区在线 | 亚洲国产精品久久66| 爽爽精品dvd蜜桃成熟时电影院| 久久精品不卡| 国产高清在线精品一区二区三区 | 无码久久精品国产亚洲Av影片| 国产综合成人色产三级高清在线精品发布| 99久久精品国产高清一区二区| 亚洲精品乱码久久久久久中文字幕 | 久久91精品国产91久久户| 色欲久久久天天天综合网精品| 久久丝袜精品中文字幕| 国产精品高清2021在线| 欧美一卡2卡3卡四卡海外精品| 国产麻豆一精品一AV一免费| 亚洲av永久无码精品表情包| 久久精品国产亚洲AV不卡| 99久久亚洲综合精品成人| 久久精品国产亚洲av水果派| 亚洲精品国偷自产在线| 欧美精品一二区| 精品久久人人妻人人做精品| 国产精品99精品视频网站| 永久免费精品视频| 久久夜色精品国产亚洲| 2021久久精品国产99国产精品| 精品亚洲成a人片在线观看少妇| 日韩精品无码一区二区三区免费| 亚洲av午夜成人片精品电影| 四虎精品成人免费视频| 少妇亚洲免费精品| 欧美人与性动交α欧美精品成人色XXXX视频 | 全球AV集中精品导航福利| 亚洲精品成人网站在线观看 | 国产小呦泬泬99精品|