當前位置:成語大全網 - 漢語詞典 - c編程詞典pdf

c編程詞典pdf

#包含“stdio.h”

#包含" string.h "

#定義N_1 3

#定義N_2 20

#定義N_3 200

int i,j;

/**************************************/

int strcmp(char * str 1,char *str2)

{

int len

int len _ 1 = strlen(str 1);

int len _ 2 = strlen(str 2);

for(I = 0;str1[i]!='\0';i++)

{

if(str 1[I]& gt;= ' A ' & amp& ampstr 1[I]& lt;= ' Z '){ str 1[I]+= 32;}

}

for(I = 0;str2[i]!='\0';i++)

{

if(str 2[I]& gt;= ' A ' & amp& ampstr 2[I]& lt;= ' Z '){ str 2[I]+= 32;}

}

len = len _ 1 & gt;len_2?len _ 2:len _ 1;

for(I = 0;我& ltleni++)

{

if(str 1[I]& gt;str 2[I]){ return 1;}

else if(str 1[I]& lt;str 2[I]){ return-1;}

}

if((len_1!= len _ 2)& amp;& amp(len _ 1 & gt;len _ 2)){ return 1;}

else if((len_1!= len _ 2)& amp;& amp(len _ 1 & lt;len _ 2)){ return-1;}

else { return 0;}

}

/**************************************/

void排序(char words[][N_2],char comments[][N_3])

{

int i,j;

char temp _ 1[N _ 2];

char temp _ 2[N _ 3];

for(I = 0;我& ltn _ 1;i++)

{

for(j = I+1;j & ltn _ 1;j++)

{

if(strcmp(words[I],words[j])==1)

{

strcpy(temp_1,words[I]);

strcpy(words[i],words[j]);

strcpy(words[j],temp _ 1);

strcpy(temp_2,comments[I]);

strcpy(comments[i],comments[j]);

strcpy(comments[j],temp _ 2);

}

}

}

}

/**************************************/

int search(char *key,char words[][N2])

{

int bot = 0;

int top = N _ 1-1;

int mid

while(bot & lt;=頂部)

{

mid =(bot+top)/2;

if(strcmp(words[mid],key)= = 1){ top = mid-1;}

else if(strcmp(words[mid],key)= =-1){ bot = mid+1;}

else { return mid}

}

return-1;

}

/**************************************/

void main()

{

int標記;

char key[N _ 2];

char單詞[N _ 1][N _ 2];

char評論[N _ 1][N _ 3];

int i,j,k;

int strcmp(char * str 1,char * str 2);

void sort(char words[][N_2],char comments[][N _ 3]);

int search(char *key,char words[][N _ 2]);

printf(" DATA:\ n ");

for(I = 0;我& ltn _ 1;i++)

{

printf("請輸入單詞%d:\t ",I+1);

獲取(words[I]);

printf("請輸入word%d的評論:\t ",I+1);

獲取(comments[I]);

}

排序(單詞、評論);

{

printf(" \ n請輸入密鑰:");

獲取(鍵);

if(* key = = NULL){ break;}

mark=search(關鍵詞,單詞);

printf(" Comment:");

if(mark==-1)

{

printf("這個詞不存在!\ n \ n @ @ @ \ n \ n ");

}

其他

{

printf("%s\n\n^_^\n\n",comments[mark]);

}

} while(1);

}