鏈表檢索英語怎麼說及英文單詞
A. 英文文件相似度統計 C語言 最好用鏈表!
為什麼不直接用資料庫分析,分析數據當然是資料庫最快最方便。回
你可以把兩個文件,答批量替換,把空格,句號等都替換成逗號。
然後用資料庫建立兩張一樣的表,只要2個欄位就可以了,一個索引,一個單詞。
然後用導入工具,直接將逗號分割的文件導入到資料庫中的這兩張表裡。
然後用聯查語句分析。
B. 求助!單向鏈表,輸入多個英文單詞,鏈表不保留重復出現的。最後統計單詞出現次數。調試很久一直出問題
#include<stdafx.h>
#include<stdio.h>
#include<stdlib.h>
#include <string.h>
#define maxsize 20
typedef struct node
{
int freg;//頻度域,記單詞出現的次數。
char word[maxsize];//maxsize是單詞中可能含有的最多字母個數
struct node *next;
}node, *LinkedList;
LinkedList creat(int n) //建立有n(n>0)個單詞的單向鏈表,若單詞重復出現,則只在鏈表中保留一個。
{
//struct node *la;
LinkedList la;
la=(LinkedList)malloc(sizeof(node));//申請頭結點。
la->next=NULL; //鏈表初始化。
node *p,*pre;
p=(node*)malloc(sizeof(node));
pre=(node*)malloc(sizeof(node));
char a[maxsize];
for(int i=1;i<=n;i++) //建立n個結點的鏈表
{
scanf("%s",a); //a是與鏈表中結點數據域同等長度的字元數組。
p=la->next;
pre=p; //p是工作指針,pre是前驅指針。
while(p!=NULL)
{
if(strcmp(p->word,a)==0) {p->freg++;break;} //如果輸入單詞重復出現,頻度增1。
else {pre=p;p=p->next;}
}//指針後移。
if(p==NULL) //該單詞沒出現過,應插入。
{
p=(LinkedList)malloc(sizeof(node));
strcpy(p->word,a);//將鍵入的單詞輸入鏈表
p->freg=1;//統計該單詞出現次數只有1
p->next=NULL;
pre=p;
} //將新結點插入到鏈表最後。
}//結束for循環。
return(la);
}//結束creat演算法。
void CreatOut( int n)
//建立有n個單詞的單向鏈表,重復單詞只在鏈表中保留一個,最後輸出頻度最高的k個單詞。
{
LinkedList la;
la=(LinkedList)malloc(sizeof(node));//申請頭結點。
la->next=NULL; //鏈表初始化。
node *p,*pre,*q;
//p=la->next;pre=p; //p是工作指針,pre是前驅指針。
char a[maxsize];
for(int i=1;i<=n;i++) //建立n個結點的鏈表
{
scanf("%s",a); //a是與鏈表中結點數據域同等長度的字元數組。
p=la->next;
pre=la; //p是工作指針,pre是前驅指針。<========這里修改了
while(p!=NULL)
{
if(strcmp(p->word,a)==0)
{
p->freg++; //單詞重復出現,頻度增1。
pre->next=p->next; //先將p結點從鏈表上摘下,再按頻度域值插入到合適位置
pre=la;
q=la->next;
while(q && q->freg>p->freg) //這里的循環··好像有點問題
{
pre=q;
q=q->next;
}
pre->next=p;
p->next=q;
break; // <=====這里修改了
}
else
{
pre=p;
p=p->next;
} //指針後移。
}
if(p==NULL) //該單詞沒出現過,應插入到鏈表最後。
{
p=(LinkedList)malloc(sizeof(node));
strcpy(p->word,a);
p->freg=1;
//la->next=p;
p->next=NULL;
pre->next=p; //調試到這里出錯
}//if 新結點插入。
}//結束for循環建表。
int k,i=0;
scanf("%d",&k);
p=la->next;
while (p && i<k) //輸出頻度最高的k個單詞
{printf("第%3d個單詞%s出現%3d次\n",++i,p->word,p->freg);
p=p->next;
}
if (!p)
printf("給出的%d值太大\n",k);
}
void main()
{
printf("輸入單詞個數:");
int a;
scanf("%d",&a);
printf("輸入單詞個數:%d\n",a);
CreatOut(a);
return;
}
C. c語言用鏈表實現,統計一個英文文本文件中每個單詞的出現次數(詞頻統計),結果按單詞詞典序輸出到屏幕
#include <stdio.h>
#include <string.h>
int main(void)
{
int a = 0, b = 0, c = 0;
char buf[128];
FILE *fp;
/* 打開文件,文件名必須大寫 */
fp= fopen("DATA5610.TXT", "r");
if (!fp) {
printf("No 'DATA5610.TXT' found.\n");
return -1;
}
/* 逐次讀取單詞,空格或回車分割 */
while (fscanf(fp, "%s", buf) > 0) {
/* 如讀取到的單詞是 if,則a自增 1 */
if (strcmp(buf, "if") == 0)
a++;
else if (strcmp(buf, "while") == 0)
b++;
else if (strcmp(buf, "for") == 0)
c++;
}
printf("if: %d, while: %d, for: %d\n", a, b, c);
fclose(fp);
return 0;
}
D. 編程從一篇英文文獻讀入字元串,分離單詞,按指針數組加鏈表方式排序,構成單詞表,並輸出該英文文獻與單
要分割單詞,那文獻肯定有規定格式,比如每個單詞都用空格分割,你截取後插入鏈表的指定節點,這時就是個排序的過程。
E. 求程序,用c++設計,求一句話中英文單詞的頻度,用 串的匹配或者鏈表,怎麼寫啊,想要完整的程序,輸
char*strstr(constchar*s1,constchar*s2)
{
intn;//字元串偏移
if(*s2)//如果第一個字元不是 ,就執行查找
{
while(*s1)//相當於*s1!='