亚洲一级电影在线观看,九九精品无码专区免费,亚洲AV无码资源在线观看 ,欧美国产高清

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

主站蜘蛛池模板: 2020国产精品永久在线| 久久精品AⅤ无码中文字字幕蜜桃| 久久99国产精品尤物| 浪潮av色综合久久天堂| 久久精品成人无码观看不卡| 亚洲欧美日韩综合久久久久| 国模av在线| 91精品91久久久久久无码啪| 一区二区三区高清无马在线| 午夜在线不卡| 免费毛片在线| 婷婷综合在线观看丁香| 老司机精品一区在线视频 | av无码久久久久久不卡网站| 欧美日本一区二区视频在线观看| 91小视频在线播放| 成人在线观看一区| 自偷自拍三级全三级视频| 天堂av高清一区二区三区| 亚洲国模精品一区| 亚洲中文精品人人永久免费| 欧美19综合中文字幕| 毛片久久网站小视频| 国产成人永久免费视频| 少妇被黑人到高潮喷出白浆 | 日日爽日日操| 午夜亚洲www湿好爽| 夜夜躁很很躁日日躁麻豆| 国产午夜人做人免费视频网站| 国产在线一区二区在线视频| 国产成人精品日本亚洲专区| 国产资源站| 上饶县| 69久久精品无码一区二区| 丰满人妻一区二区三区视频| 奇米四色7777中文字幕| 在线亚洲97se亚洲综合在线| 一区二区三区高清视频一| 两女女百合互慰av赤裸无遮挡| 欧美黑吊大战白妞| 太康县|