当前位置: 首页 > news >正文

淮上网站建设福州短视频seo推荐

淮上网站建设,福州短视频seo推荐,建设银行代发工资清单网站,咖啡建设网站的目的文章目录 前言功能要求运行截图全部代码 前言 无套路,均已上机通过,求个关注求个赞,提供答疑解惑服务。 功能要求 一份C源代码存储在一个文本文件中,请统计该文件中关键字出现的频度,并按此频度对关键字进行排序。要…

文章目录

  • 前言
  • 功能要求
  • 运行截图
  • 全部代码

前言

无套路,均已上机通过,求个关注求个赞,提供答疑解惑服务。

功能要求

一份C源代码存储在一个文本文件中,请统计该文件中关键字出现的频度,并按此频度对关键字进行排序。要求:

  • 从文本文件InFile.txt读取C源代码,从文本文件Key.txt读取关键字列表。
  • 分别采用如下不同的查找策略进行频度统计:
    • 链式存储上的顺序查找;
    • 基于链地址法的哈希查找。
  • 基于快速排序实现关键字排序。
  • 不论采取哪种查找和排序策略,完成功能均相同。
    • 关键字统计:依次从关键字列表Key.txt中读取关键字,若该关键字未在文本文件InFile.txt中出现,则将其频度计为0;每检索到一次该关键字,则将其频度增加1。统计结束后,将所有关键字及其频度按关键字列表顺序写入文本文件中。其中,无论关键字列表中的关键字是否出现都要计数。不同查找策略所获得的结果分别写入不同的文件(OutFile1.txt,OutFile2.txt)。
    • 关键字排序:根据关键字出现的频度对所有关键字进行从高到低排序,舍弃关键字列表中未出现的关键字。如果关键字出现的频度相等,则按照关键字的首字母从小到大排序,将排序后的关键字及其频度写入文本文件(OutFile3.txt)中。
  • 设计菜单,实现上述功能。

运行截图

在这里插入图片描述

全部代码

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>#define MAX_KEYWORDS 100
#define MAX_KEYWORD_LENGTH 50
#define HASH_TABLE_SIZE 101typedef struct {char keyword[MAX_KEYWORD_LENGTH];int frequency;
} KeywordInfo;typedef struct HashNode {KeywordInfo data;struct HashNode *next;
} HashNode;typedef struct {HashNode *table[HASH_TABLE_SIZE];
} HashTable;int compareKeywords(const void *a, const void *b) {const KeywordInfo *keywordA = (const KeywordInfo *)a;const KeywordInfo *keywordB = (const KeywordInfo *)b;if (keywordB->frequency != keywordA->frequency) {return keywordB->frequency - keywordA->frequency;}return strcmp(keywordA->keyword, keywordB->keyword);
}void initializeHashTable(HashTable *hashTable) {int i;for (i = 0; i < HASH_TABLE_SIZE; i++) {hashTable->table[i] = NULL;}
}unsigned int hashFunction(const char *str) {unsigned int hash = 0;while (*str) {hash = (hash << 5) + *str++;}return hash % HASH_TABLE_SIZE;
}HashNode *searchHashTable(HashTable *hashTable, const char *keyword) {unsigned int hashValue = hashFunction(keyword);HashNode *current = hashTable->table[hashValue];while (current != NULL) {if (strcmp(current->data.keyword, keyword) == 0) {return current;}current = current->next;}return NULL;
}void insertHashTable(HashTable *hashTable, const KeywordInfo *keywordInfo) {unsigned int hashValue = hashFunction(keywordInfo->keyword);HashNode *newNode = (HashNode *)malloc(sizeof(HashNode));if (newNode == NULL) {printf("内存分配失败\n");exit(1);}newNode->data = *keywordInfo;newNode->next = hashTable->table[hashValue];hashTable->table[hashValue] = newNode;
}void freeHashTable(HashTable *hashTable) {int i;for (i = 0; i < HASH_TABLE_SIZE; i++) {HashNode *current = hashTable->table[i];while (current != NULL) {HashNode *next = current->next;free(current);current = next;}}
}void countKeywordsSequential(FILE *file, char *keywords[], int numKeywords, KeywordInfo keywordInfo[]) {char line[1024];rewind(file);while (fgets(line, sizeof(line), file) != NULL) {for (int i = 0; i < numKeywords; i++) {char *pos = strstr(line, keywords[i]);while (pos != NULL) {if ((pos == line || !isalpha(pos[-1])) && !isalpha(pos[strlen(keywords[i])])) {keywordInfo[i].frequency++;}pos = strstr(pos + 1, keywords[i]);}}}
}void countKeywordsHash(FILE *file, HashTable *hashTable, char *keywords[], int numKeywords, KeywordInfo keywordInfo[]) {char line[1024];rewind(file);while (fgets(line, sizeof(line), file) != NULL) {for (int i = 0; i < numKeywords; i++) {char *pos = strstr(line, keywords[i]);while (pos != NULL) {if ((pos == line || !isalpha(pos[-1])) && !isalpha(pos[strlen(keywords[i])])) {// 检查哈希表中是否已存在该关键字的节点HashNode *existingNode = searchHashTable(hashTable, keywords[i]);if (existingNode != NULL) {// 如果已存在,则更新哈希表中节点的频度existingNode->data.frequency++;} else {// 如果不存在,则插入新节点到哈希表KeywordInfo newKeywordInfo = { .frequency = 1 };strcpy(newKeywordInfo.keyword, keywords[i]);insertHashTable(hashTable, &newKeywordInfo);}// 更新数组中的频度keywordInfo[i].frequency++;}pos = strstr(pos + 1, keywords[i]);}}}
}void writeKeywordStats(FILE *outputFile, KeywordInfo keywordInfo[], int numKeywords) {for (int i = 0; i < numKeywords; i++) {fprintf(outputFile, "%s: %d\n", keywordInfo[i].keyword, keywordInfo[i].frequency);}
}void writeSortedKeywordStats(FILE *outputFile, KeywordInfo keywordInfo[], int numKeywords) {for (int i = 0; i < numKeywords; i++) {if (keywordInfo[i].frequency > 0) {fprintf(outputFile, "%s: %d\n", keywordInfo[i].keyword, keywordInfo[i].frequency / 2);}}
}void writeHashTableStats(FILE *outputFile, HashTable *hashTable, char *keywords[], int numKeywords) {for (int i = 0; i < numKeywords; i++) {HashNode *node = searchHashTable(hashTable, keywords[i]);fprintf(outputFile, "%s: %d\n", keywords[i], (node != NULL) ? node->data.frequency : 0);}
}void sortKeywords(KeywordInfo keywordInfo[], int numKeywords) {qsort(keywordInfo, numKeywords, sizeof(KeywordInfo), compareKeywords);
}int main(void) {FILE *keywordFile, *codeFile;FILE *outputFile1, *outputFile2, *outputFile3;char *keywords[MAX_KEYWORDS];int numKeywords = 0;char tempKeyword[MAX_KEYWORD_LENGTH];KeywordInfo keywordInfo[MAX_KEYWORDS];HashTable hashTable;// 打开文件keywordFile = fopen("Key.txt", "r");codeFile = fopen("InFile.txt", "r");outputFile1 = fopen("OutFile1.txt", "w");outputFile2 = fopen("OutFile2.txt", "w");outputFile3 = fopen("OutFile3.txt", "w");if (keywordFile == NULL || codeFile == NULL || outputFile1 == NULL || outputFile2 == NULL || outputFile3 == NULL) {printf("无法打开文件\n");return 1;}// 读取关键字列表while (fscanf(keywordFile, "%s", tempKeyword) != EOF && numKeywords < MAX_KEYWORDS) {keywords[numKeywords] = (char *)malloc(strlen(tempKeyword) + 1);strcpy(keywords[numKeywords], tempKeyword);numKeywords++;}// 初始化关键字信息数组for (int i = 0; i < numKeywords; i++) {strcpy(keywordInfo[i].keyword, keywords[i]);keywordInfo[i].frequency = 0;}// 初始化哈希表initializeHashTable(&hashTable);int choice;do {// 显示菜单printf("\n菜单:\n");printf("1. 顺序查找关键字并统计频度(输出到OutFile1.txt)\n");printf("2. 哈希查找关键字并统计频度(输出到OutFile2.txt)\n");printf("3. 排序关键字并输出到OutFile3.txt\n");printf("4. 退出\n");printf("请选择操作: ");scanf("%d", &choice);switch (choice) {case 1:// 顺序查找关键字并统计频度countKeywordsSequential(codeFile, keywords, numKeywords, keywordInfo);writeKeywordStats(outputFile1, keywordInfo, numKeywords);break;case 2:// 哈希查找关键字并统计频度countKeywordsHash(codeFile, &hashTable, keywords, numKeywords, keywordInfo);writeHashTableStats(outputFile2, &hashTable, keywords, numKeywords);break;case 3:// 排序关键字并输出sortKeywords(keywordInfo, numKeywords);writeSortedKeywordStats(outputFile3, keywordInfo, numKeywords);break;case 4:// 退出break;default:printf("无效的选项,请重新选择\n");break;}} while (choice != 4);// 关闭文件和释放内存fclose(keywordFile);fclose(codeFile);fclose(outputFile1);fclose(outputFile2);fclose(outputFile3);for (int i = 0; i < numKeywords; i++) {free(keywords[i]);}freeHashTable(&hashTable);return 0;
}
http://www.hkea.cn/news/785270/

相关文章:

  • 淘宝网站内搜索引擎优化怎么做广告推广平台网站有哪些
  • 大片播放网站国外免费推广网站有哪些
  • flash网站cms排名sem优化软件
  • 申请完域名怎么做网站百度链接提交
  • 驻马店市可以做网站的公司百度搜索竞价排名
  • 郑州市做网站吉林百度查关键词排名
  • 济宁网站建设seo抖音seo源码搭建
  • 茂名网站建设方案书简述seo和sem的区别
  • 江西网站做的好的企业文化百度指数在哪里看
  • 山东电商网站建设seo网站排名优化公司
  • 赤峰市做网站公司今日的最新消息
  • 上海最大的贸易公司seo网络推广机构
  • jsp 网站开发广告发布平台
  • b2c网站综合对比评价站长统计幸福宝
  • 网站建设意见做推广app赚钱的项目
  • 哈尔滨营销网站制作做外贸推广
  • 深圳网站建设外贸公司排名搜索热词排名
  • 网络科技公司招聘可靠吗seo多久可以学会
  • 企业网站建设的方案ppt网络营销的特点主要包括什么
  • 如何自行建设网站推广关键词优化
  • 建设学院网站百度收录关键词查询
  • 有关外贸的网站有哪些内容武汉抖音seo搜索
  • 娄底网站建设的话术深圳网站关键词排名优化
  • 福田大型商城网站建设seo营销方法
  • 网站开发专业就业指导企业网站设计与实现论文
  • 网络营销方式的思维导图seo关键词优化系统
  • wordpress访客ip记录福清市百度seo
  • 网站下载速度慢互联网广告推广公司
  • 电影网站空间配置网络营销的工具和方法有哪些
  • 包装设计网站免费百度seo搜索引擎优化厂家