當前位置:首頁 » 編程語言 » 單詞查詢系統c語言
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

單詞查詢系統c語言

發布時間: 2022-04-29 07:05:13

1. 一個c語言程序,單詞測試系統需要設計哪些方面

編程語言:C語言

程序目標:從一個txt文件中讀取字元,識別其中每一個英文單詞。

數據結構:鏈表,結構體

基本思路:最外層循環判斷條件是文件中有數據讀取,每次從文件中讀取一個字元,判斷是否是字母,每次讀取到空格就說明一個單詞的結束,然後把得到的單詞插入到鏈表中,鏈表中每一個節點存儲

一個單詞,並記錄該單詞的頻數,插入規則是,有該單詞,則增加頻數,否則插入到鏈表。最後從鏈表中選取頻數最大的是個節點輸出。分析結論:第一張圖顯示的CPU消耗時間主要是在前面部分,這跟我的代碼是相對應的,在主函數的調用過程中,前面部分是讀取數據,構建相關數據結構,因而資源消耗大。第二張圖顯示,creatlist

函數中分為子函數和不包含子函數對資源的消耗,不包含子函數的獨占樣本百分百要多,說明creatlist函數在演算法上比creatnode函數要復雜一些,這也跟處理該問題的主體演算法思路有關。第三章圖顯

示的creatlist函數的消耗資源最多,其次是庫函數strcmp,因為creatlist函數在構建的時候,要判斷是插入節點還是直接增加某個節點的頻數,因而需要搜素鏈表,所以要消耗很多資源,在搜索過程

2. 用c語言編寫一個背單詞的系統 大神們幫幫忙啊!!!!

Y花點真的Money吧,這也算一個較大的程序吧

3. 寫一條查找單詞數的C語言

#include <stdio.h>
main()
{
char c[10],d[10];
int i=0,a=0,p=1,k=0;
printf("輸入一個單詞,以空格結束\n");
while(i<10)
{c[i]=getchar();
i++;
if (c[i-1]==' ')
{printf("請輸入文章,以0結束\n");break;}}
show:
while(a<10)
{ d[a]=getchar();
if(d[a]=='0')
break;
if (d[a]==' ')
{ i=0;
while ((i<=9)&&(c[i]==d[i]))
i++;
if(i==a+1)
{ p++;k++;a=0;
goto show;}
else
{k++;
a=0;
if(k<=1000)
goto show;}

}
a++;
}
printf("一共有%d個",p);
}

這里只給出有幾個,位置就自己加一下吧,我也剛學

4. 查詢單詞 C語言如何實現

你一個一個字元的來判斷.你可以設定一個變數來表示一個單詞的開始和結束.flag=0時是沒有單詞,當flag=1時一個單詞的開始.那flag=1即單詞開始時掃描的是字元繼續下個字元的,如果是非字元flag=0;到下個字元開始是flag=1;那一個單詞的開始到結束就是一個單詞了,你可以設定一個變數來記錄單詞的個數.

5. 用C語言編寫設計一個簡易的星期單詞查詢系統。即:從鍵盤輸入星期幾的數字,顯示出相應的英語單詞。

摘要 Problem G: C語言實驗——輸入數字星期,輸出英文(選擇結構-switch)

6. 用C語言寫:檢索英文單詞程序

#include<stdio.h>
#include<string.h>
#define MAX_size 1000
int flag=1,degree=0;
void Index(char str[],char word[],int position[])
{
int i,len_str,len_word,pos_str,pos_word,k=0,word_number=0;//word_number代表短文中單詞的個數
len_word=strlen(word);
len_str=strlen(str);
for(i=0;i<len_str;)
{
while(str[i]==' ')
i++;
word_number++; //單詞個數加一
for(pos_str=i,pos_word=0;pos_str<len_str && pos_word<len_word;pos_str++,pos_word++)
{
if(str[pos_str]!=word[pos_word])
break;
}
if(pos_word==len_word && (str[pos_str]=='\0'|| str[pos_str]==' ' )) //表明找到相等的單詞
{
position[k++]=word_number;
degree++; //相等的次數加1
flag=0;
}
else
{
while(str[pos_str]!=' ' && pos_str<len_str)
pos_str++;
}
i=pos_str;
}
}
void main()
{
char str[MAX_size],word[20];

int position[100],i;
printf("請輸入一行英文短文: \n");
gets(str);
printf("請輸入要檢索的單詞: \n");
gets(word);
Index(str,word,position);
if(flag)
printf("您輸入的單詞不在短文中。\n");
else
{
printf("您輸入的單詞在短文中,它共出現 %-d 次\n",degree);
printf("出現的位置為: \n");
for(i=0;i<degree;i++)
printf("第%-2d個單詞\n",position[i]);
}
}//未考慮逗號,若要考慮則加幾個判斷條件即可

7. 用c語言編寫背單詞系統要求背單詞和測驗,瀏覽單詞

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
structword
{
charenglish[30];
charchinese[100];
intcount;/*記錄背單詞的正確次數*/
}dic[4000];
chargetChoice()
{
charstr[10];
gets(str);
while(strlen(str)==0)
{
printf("輸入為空,請重新輸入:");
gets(str);
}
returnstr[0];
}

intmain()
{
FILE*fp;
charch,line[100];
intkong,i,count=0,j=0,end=0,k=0;
intlast_process=0;

if((fp=fopen("cet4.txt","r"))==NULL)
{
printf("cannotopenthetxt!!! ");
exit(0);
}

/*讀取所有單詞*/
while(fgets(line,sizeof(line),fp)!=0)
{
/*每一行記錄的格式【單詞中文正確數】*/


/*讀取單詞*/
j=0;
for(i=0;i<line[i]!='';i++)
{
dic[count].english[j]=line[i];
j++;
}
dic[count].english[i]='';

/*特殊處理,如果這個欄位是自定義的上次進度標記,則記下進度,假如進度標記是#last_process#*/
if(strcmp(dic[count].english,"#last_process#")==0)
{
last_process=atoi(line+i+1);
continue;
}

/*讀取中文*/
j=0;
for(i=kong+1;i<line[i]!='';i++)
{
dic[count].chinese[j]=line[i];
j++;
}
dic[count].chinese[j]='';

/*正確數*/
dic[count].count=atoi(line+i+1);

count++;
}
fclose(fp);

/*列印下讀取的信息*/
printf("單詞數:%d 上次背到第%d個單詞 ",count,last_process);

/*while*/
/*這里背單詞策略,可以根據count來判斷單詞熟悉度,該值越大表示越熟悉*/
/*負數表示記錯了的次數,錯的越多,負的越大*/
i=last_process;
while(ch!=0)
{
//可根據需要排序單詞,排序依據是count欄位大小
puts(" 1.隨機20個單詞測試 ");
puts(" 2.強化記憶 ");
puts(" 前一個(P)後一個(N)收藏(C)結束瀏覽(M)");
while(ch!=0)
{
ch=getChoice();
if(ch=='P'||ch=='p')
{
i=(last_process+count-1)%count;
printf("%s ",dic[i].english);
printf("%s ",dic[i].chinese);
}

if(ch=='N'||ch=='n')
{
i=(last_process+1)%count;
printf("%s ",dic[i].english);
printf("%s ",dic[i].chinese);
}
elseif(ch=='C'||ch=='c')
{
printf("已經加入單詞本");
}

if(ch=='M'||'m')
{
break;
}
}
}

/*程序退出*/
last_process=i;
if((fp=fopen("cet4.txt","w"))==NULL)
{
printf("cannotopenthetxt!!! ");
exit(0);
}
/*把單詞進入重新寫入單詞文件*/
for(i=0;i<count;i++)
{
fprintf(fp,"%s%s%d ",dic[i].english,dic[i].chinese,dic[i].count);
}
fprintf(fp,"#last_process#%d",last_process);
fclose(fp);

return0;
}

大致這樣子,懶得寫了~~~有需要可討論

8. C語言 單詞檢索程序

=====================================
問題補充:二樓的是死循環運行不了啊
=====================================
實在抱歉,之前疏忽了,現在已經改好了,再試一下吧:)

=====================================
問題補充:二樓的幸苦了,仔細看了一下你的,好像有點出入,不是自己輸入文章,是打開已有文章。還得麻煩你稍稍修改下。謝謝哈
=====================================
根據你的要求,又改了一版,現在已經改好了,再試一下吧:)
給:
#include<stdio.h>
#include<string.h>
#define MAX_size 1000
int flag=1,degree=0;
void Index(char str[],char word[],int position[])
{
int i,len_str,len_word,pos_str,pos_word,k=0,word_number=0;//word_number代表短文中單詞的個數
len_word=strlen(word);
len_str=strlen(str);
for(i=0;i<len_str;i++)
{
while(str[i]==' '||str[i]==','||str[i]=='.')
i++;
word_number++; //單詞個數加一
for(pos_str=i,pos_word=0;pos_str<len_str && pos_word<len_word;pos_str++,pos_word++)
{
if(str[pos_str]!=word[pos_word])
break;
}
if(pos_word==len_word && (str[pos_str]=='\0'|| str[pos_str]==' '||str[pos_str]==','||str[pos_str]=='.')) //表明找到相等的單詞
{
position[k++]=word_number;
degree++; //相等的次數加1
flag=0;
}
else
{
while(str[pos_str]!=' '&&str[pos_str]==','&&str[pos_str]=='.'&& pos_str<len_str)
pos_str++;
}
i=pos_str;
}
}
void main()
{
char str[MAX_size],word[20],ch;
int position[100],i;

int k=0;
FILE *fp;

if((fp=fopen("a.txt","r"))!=NULL)
{
while(1)
{
ch=fgetc(fp);
if(ch==EOF) break;

str[k]=ch;
k++;
}
}

printf("請輸入要檢索的單詞: \n");
gets(word);
Index(str,word,position);
if(flag)
printf("您輸入的單詞不在短文中。\n");
else
{
printf("您輸入的單詞在短文中,它共出現 %-d 次\n",degree);
printf("出現的位置為: \n");
for(i=0;i<degree;i++)
printf("第%-2d個單詞\n",position[i]);
}
fclose(fp);
}

9. 輸入前幾個字母就能找出這個單詞的模糊查找,用c語言如何編程

給你個思路,每次查找都至少找到5個結果才結束,一個單詞,先獲取單詞部分,根據輸入長度截取單詞,只要匹配就可以。
在高級點一個單詞,先獲取單詞部分,再遍歷單詞,按照輸入的長度 每次截取那麼長再比較,
如果你會連接資料庫就不用這些代碼了,直接用LIKE %%。

10. 用C語言編程,如何查找一段文字(有英有漢)中的某些英文單詞,並統計其數量

//search.c
#include <stdio.h>
#include <conio.h>
main()
{
FILE*fp;
char key[20],ch;
int i,l,num=0;
if((fp=fopen("d:\\word.dat","w+"))==NULL)
{ printf("can not open file");
getch();
exit(0);
}
printf("輸入文章(按#鍵結束)_\n ");
do{
ch=getchar();
fputc(ch,fp);
}while(ch!='#');
getchar();
printf("\n輸入要查詢的關鍵字_ ");
gets(key);
rewind(fp);
ch=fgetc(fp);
while(ch!=EOF)
{
if(ch==key[0])
{
l=strlen(key);
for(i=1;i<l;i++)
{
ch=fgetc(fp);
if(ch!=key[i]) break;
}
num++;

}
ch=fgetc(fp);
}
printf("共計: %d (%s)\n",num,key);
getch();
}