當(dāng)前位置:高考升學(xué)網(wǎng) > 招聘筆試題 > 正文
二. 填空題(共40分)
本程序從正文文件text.in讀入一篇英文短文,統(tǒng)計(jì)該短文中不同單詞和它的出現(xiàn)次數(shù),并按詞典編輯順序?qū)卧~及它的出現(xiàn)次數(shù)輸出到正文文件word.out中.
程序用一棵有序二叉樹(shù)存儲(chǔ)這些單詞及其出現(xiàn)的次數(shù),一邊讀入一邊建立.然后中序遍歷該二叉樹(shù),將遍歷經(jīng)過(guò)的二叉樹(shù)上的節(jié)點(diǎn)的內(nèi)容輸出.
程序中的外部函數(shù)
int getword(FILE pFile,char pszWordBuffer,int nBufferLen);
從與pFile所對(duì)應(yīng)的文件中讀取單詞置入pszWordBuffer,并返回1;若單詞遇文件尾,已無(wú)單詞可讀時(shí),則返回0.
#include
#include
#include
#include
#define SOURCE_FILE "text.in"
#define OUTPUT_FILE "word.out"
#define MAX_WORD_LEN 128
typedef struct treenode
{
char szWord[MAX_WORD_LEN];
int nCount;
struct treenode pLeft;
struct treenode pRight;
}BNODE;
int getword(FILE pFile,char pasWordBuffer,int nBufferLen);
void binary_tree(BNODE ppNode,char pszWord)
{
if(ppNode != NULL && pszWord != NULL)
{
BNODE pCurrentNode = NULL;
BNODE pMemoNode = NULL;
int nStrCmpRes=0;
____(1)_____;pCurrentNode=ppNode
while(pCurrentNode)
{
/尋找插入位置/
nStrCmpRes = strcmp(pszWord, ___(2)___ );pCurrentNode->nCount
if(!nStrCmpRes)
{
___(3)___; pCurrentNode->nCount++
return;
}
else
{
___(4)___; pMemoNode=pCurrentNode
pCurrentNode = nStrCmpRes>0? pCurrentNode->pRight : pCurrentNode->pLeft;
}
}
}
pCurrent=new BNODE;
if(pCurrentNode != NULL)
{
memset(pCurrentNode,0,sizeof(BNODE));
strncpy(pCurrentNode->szWord,pszWord,MAX_WORD_LEN-1);
pCurrentNode->nCount=1;
}
if(pMemoNode==NULL)
{
___(5)___; ppNode= pCurrentNode
}
else if(nStrCmpRes>0)
{
pMemoNode->pRight=pCurrentNode;
}
else
{
pMemoNode->pLeft=pCurrentNode;
}
}
void midorder(FILE pFile,BNODE pNode)
{
if(___(6)___) return;!pNode||!pFile
midorder(pFile,pNode->pLeft);
fprintf(pFile,"%s %d\n",pNode->szWord,pNode->nCount);
midorder(pFile,pNode->pRight);
}
void main()
{
FILE pFile=NULL;
BNODE pRootNode=NULL;
char szWord[MAX_WORD_LEN]={0};
pFile=fopen(SOURCE_FILE,"r");
if(pFile==NULL)
{
printf("Can't open file %s\n",SOURCE_FILE);
return;
}
while(getword(pFile,szWord,MAX_WORD_LEN)==1)
{
binary_tree(___(7)___);// pRootNode,szWord
}
fclose(pFile);
pFile=fopen(OUTPUT_FILE,"w");
midorder(pFile,pRootNode);
fclose(pFile);
}
三. 附加題(每題30分,2題,共60分)
1. 從程序健壯性進(jìn)行分析,下面的FillUserInfo函數(shù)和Main函數(shù)分別存在什么問(wèn)題?
#include
#include
#define MAX_NAME_LEN 20
struct USERINFO
{
int nAge;
char szName[MAX_NAME_LEN];
};
void FillUserInfo(USERINFO parUserInfo)
{
stu::cout<<"請(qǐng)輸入用戶的個(gè)數(shù):";
int nCount=0;
std::cin>>nCount;
for(int i=0;i
{
std::cout<<"請(qǐng)輸入年齡:";
std::cin>>parUserInfo[i]->nAge;
std::string strName;
std::cout<<"請(qǐng)輸入姓名:";
std::cin>>strName;
strcpy(parUserInfo[i].szName,strName.c_str());
}
}
int main(int argc,char argv[])
{
USERINFO arUserInfos[100]={0};
FillUserInfo(arUserInfos);
printf("The first name is:");
printf(arUserInfos[0].szName);
printf("\n");
return 0;
}
2. 假設(shè)你在編寫(xiě)一個(gè)使用多線程技術(shù)的程序,當(dāng)程序中止運(yùn)行時(shí),需要怎樣一個(gè)機(jī)制來(lái)安全有效的中止所有的線程?請(qǐng)描述其具體流程.
2020年河北新聞網(wǎng)兩學(xué)一做
時(shí)間:2023-09-18 07:0:242020年河北新聞網(wǎng)兩學(xué)一做
時(shí)間:2023-09-15 11:0:59兩學(xué)一做學(xué)習(xí)教育知
時(shí)間:2023-09-21 06:0:302020年開(kāi)展兩學(xué)一做學(xué)習(xí)教
時(shí)間:2023-09-19 21:0:30