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

东莞网络公司 网站建设洛阳网站建设行业

东莞网络公司 网站建设,洛阳网站建设行业,wordpress 风 轩,苏州现代建设公司网站C语言构建定长字典 1.C语言简介-struct C语言中没有字典。而有些场合下需要统计一些字符串变量的累计值#xff0c;就需要用定长字典。定长字典顾名思义就是长度固定的字典。在C语言中结构体可以定义任意类型数据的集合#xff0c;也就可以通过结构体数组来构造个定长字典。…C语言构建定长字典 1.C语言简介-struct C语言中没有字典。而有些场合下需要统计一些字符串变量的累计值就需要用定长字典。定长字典顾名思义就是长度固定的字典。在C语言中结构体可以定义任意类型数据的集合也就可以通过结构体数组来构造个定长字典。 2.词频字典 2.1词频字典结构体 /* 词频字典结构体 */#define WORD_MAX_SIZE 100 struct word_fre_dict {char word[WORD_MAX_SIZE]; /* 假设单词长度最长为100 */int times; /* 在一篇文章出现次数不超过 2^31 - 1次 */ }; typedef struct word_fre_dict WORD_FRE_DICT; 2.2 词频字典的排序 /* 可以用qsort函数进行排序 *//* 按字典序排序 */ int cmp_dict(const void *a, const void *b) {WORD_FRE_DICT *pa (WORD_FRE_DICT *)a; WORD_FRE_DICT *pb (WORD_FRE_DICT *)b;return strcmp(pa-word, pb-word); } /* 按词频从小到大排序 */ int cmp_fre_up(const void *a, const void *b) {WORD_FRE_DICT *pa (WORD_FRE_DICT *)a; WORD_FRE_DICT *pb (WORD_FRE_DICT *)b;return (pa-times - pb-times); } /* 按词频从大到小排序 */ int cmp_fre_down(const void *a, const void *b) {WORD_FRE_DICT *pa (WORD_FRE_DICT *)a; WORD_FRE_DICT *pb (WORD_FRE_DICT *)b;return (pb-times - pa-times); }2.3 从字符串文本中提取词频字典 void create_word_fre_dict(char* paragraph) {WORD_FRE_DICT word_list[1000] { 0 };memset(word_list, 0, 1000 * sizeof(WORD_FRE_DICT));/* 预处理 单词全改为小写, 非单词全转为空格符 */int i 0;while (paragraph[i] ! 0) {if (paragraph[i] A paragraph[i] Z) {tolower(paragraph[i]);}else if ((paragraph[i] A || paragraph[i] Z) \((paragraph[i] a || paragraph[i] z))) {paragraph[i] ;}i;}/* 使用strtok公式进行字符串拆分 */char* temp strtok(paragraph, );strcpy(word_list[0].word, temp);word_list[0].times;while (temp ! NULL) {temp strtok(NULL, ); /* 最后一个字节拿出来后还会执行一次这次结果为NULL */if (temp NULL) {break;}printf(%s\n, temp);int dict_index 0;int find 0;while (word_list[dict_index].times ! 0 dict_index 1000) {if (strcmp(word_list[dict_index].word, temp) 0) {word_list[dict_index].times;find 1;break;}dict_index;}if (!find dict_index 1000) {strcpy(word_list[dict_index].word, temp);word_list[dict_index].times 1;}}qsort(word_list, 50, sizeof(WORD_FRE_DICT), cmp_dict);for (int de 0; de 20; de) {printf(%s, count %d\n, word_list[de].word, word_list[de].times);} }int c_dict_test(void) {char para[] { Youth means a temperamental predominance of courage over timidity, \of the appetite for adventure over the love of ease. This often \exits in a man of 60, more than a boy of 20.nobody grows merely \by the number of years; we grow old by deserting our ideas. Years \may wrinkle the skin, but to give up enthusiasm wrinkles the soul. \Worry, fear, self distrust bows the heart and turns the spirit \back to dust. };printf(%s\n, para);create_word_fre_dict(para);return 0; }
http://www.huolong8.cn/news/71258/

相关文章:

  • asp婚纱摄影网站源码无经验可以做网站编辑吗
  • 网站整体设计流程产品推广营销方案
  • wordpress外贸网站增加个博客栏信誉楼线上商城小程序
  • 广宗网站建设营销型网站深度网
  • 国内简洁网站设计延吉 网站开发
  • 成都网站建设制作价格品牌建设综述
  • 网站开发合同需要交印花税吗网站开发运营经理
  • 做网站链接要多少钱固始县住房和城乡规划建设局网站
  • 合适的网站建设的公司怎么找搜索推广网站哪家做的最好
  • 网站管理建设的总结免费广告平台
  • 网站管理助手 建设中网站建设视频教程云盘
  • 通化市住房和城乡建设局网站提供佛山网站制作
  • 建设厅注册中心网站考试报名费缴费1G免费网站空间
  • 网站发布 图片看不到企业网站404页面设计
  • 宝山网站建设公司中国建行网站
  • php旅游网站开发背景互联网行业未来发展趋势
  • 视屏网站开发者工具无视频文件土特产网站建设事业计划书
  • 自己怎么做卡密网站可以做动漫网站的源码源码
  • 做网站平台需要什么条件网站如何做快排
  • 网站建设制作临沂网站建设选盛誉做新零售这些注册网站和找货源6
  • 网站建立后怎么做推广怎么样通过做网站赚钱
  • 网站投票怎么做南昌诚推网络技术有限公司
  • 沈阳网站推广公司网站上的qq咨询怎么做
  • 网站 二级域名需要备案吗网站有情链接怎么做
  • 做分析仪器推广的网站wordpress许愿墙
  • 教做家常菜的视频网站网页设计尺寸怎么设计
  • 网站基本代码网站设计与制作教程1
  • php 网站 教程网站建设成都云
  • 上海专业网站建站品牌网站开发中设置会员等级
  • 如何建网站平台为什么要做手机网站