文学研究助手(设计性实验)

1. 需求分析

需求:
英文小说存于一个文本文件中。待统计的词汇集合要一次输入完毕,即统计工作必须在程序的一次运行之后就全部完成。程序的输出结果是每个词的出现次数和出现位置的行号,格式自行设计。
分析:
(1) 输入的形式和输入值的范围:将英语文章按屏幕提示放入文件中,输入查找个数为int型数字,输入英文单词为字符串形式。
(2) 输出的形式:输出int型数字,放在文件“统计词汇的结果.txt”中。
(3) 程序所能达到的功能:统计要查找的单词在文件中的个数。
(4) 测试数据:
· 以程序源代码作为英语文章放入文件中
· 查找3个单词:include while break

2. 概要设计

  1. 为了实现程序功能,需要定义串的抽象数据类型。
ADT String {数据对象:D={ ai |ai∈CharacterSet, i=1,2,...,n, n≥0 }数据关系:R1={ < ai-1, ai > | ai-1, ai ∈D, i=2,...,n }typedef struct WORD{char letter;struct WORD *next;
}word;                //单词节点 typedef struct{word *first;word *last;
}row;                  //行结构节点 typedef struct Row{row r;struct ROW *next;
}ROW;                    //行结构 typedef struct{ROW *first;ROW *last;
}article;            //文章结构基本操作:
StrAssign (&T, chars)初始条件:chars 是字符串常量。操作结果:把 chars 赋为 T 的值。
StrCopy (&T, S)初始条件:串 S 已存在。操作结果:由串 S 复制得到串 T。
DestroyString (&S)初始条件:串 S 已存在。操作结果:串 S 被销毁。
StrEmpty (S)初始条件:串S已存在。操作结果:若 S 为空串,则返回 TRUE,否则返回 FALSE。
StrLength (S)初始条件:串 S 已存在。操作结果:返回 S 的元素个数,称为串的长度。
StrCompare (S, T)初始条件:串 S 和 T 已存在。操作结果:若S > T,则返回值> 0; 若S = T,则返回值=0; 若S < T,则返回值<0。
Concat (&T, S1, S2)初始条件:串 S1 和 S2 已存在。操作结果:用 T 返回由 S1 和 S2联接而成的新串。
SubString (&Sub, S, pos, len)初始条件:串S 已存在,1<=pos<=StrLength(S) 且 0<=len<=StrLength(S)-pos+1。操作结果: Sub 返回串 S 的第 pos 个字符起长度为 len 的子串。
Index (S, T, pos)初始条件:串S和T已存在,T是非空串,1≤pos≤StrLength(S)。操作结果:若主串 S 中存在和串 T 值相同的子串, 则返回它在主串 S
中第pos个字符之后第一次出现的位置;否则函数值为0。
Replace (&S, T, V)初始条件:串S, T和 V 均已存在,且 T 是非空串。操作结果:用 V 替换主串 S 中出现的所有与(模式串)T相等的不重叠的子串。
StrInsert (&S, pos, T)初始条件:串S和T已存在,1≤pos≤StrLength(S)+1。操作结果:在串S的第pos个字符之前插入串T。
StrDelete (&S, pos, len)初始条件:串S已存在,1≤pos≤StrLength(S)-len+1。操作结果:从串S中删除第pos个字符起长度为len的子串。
ClearString (&S)初始条件:串S已存在。操作结果:将S清为空串。
}ADT String

3.具体代码

  • 文章结构链表.h:
typedef struct WORD{char letter;//字母 struct WORD *next;//下一个字母
}word;                //单词节点 typedef struct{word *first;//头字母指针 word *last;//尾字母指针
}row;                  //行结构节点 typedef struct Row{row r;//行结构节点 struct ROW *next;//下一行的结构节点
}ROW;                    //行结构 typedef struct{ROW *first;//头行指针 ROW *last;//尾行指针
}article;            //文章结构 void create_article(article *a)      //创建文章结构
{a->first = (ROW*)malloc(sizeof(ROW));//首行指针分配空间 a->first->next = NULL;a->last = a->first;//初始首位行指针相同 a->first->r.first = (word*)malloc(sizeof(word));//为首行元素分配首字母空间 a->first->r.first->next = NULL;a->first->r.last = a->first->r.first;//首行元素的首位字母指向同一个位置 a->first->r.first->letter = 1; //第一个字母
}void add_row(article *a)       //添加行
{ROW *p;p = (ROW*)malloc(sizeof(ROW));p->next = NULL;p->r.first = (word*)malloc(sizeof(word));p->r.last = p->r.first;p->r.first->letter = a->last->r.first->letter+1;a->last->next = p;a->last = p;
}void add_word(row *r,char ch)  //添加字母
{word *p;//先定义一个单词的指针 p = (word*)malloc(sizeof(word));//分配空间 p->letter = ch;//字母信息 p->next = NULL;r->last->next = p;//尾插 r->last = p;//把尾指针改变
}
  • KMP算法匹配.h:
void pretreatment(char a[],int b[])             //预处理->本质就是求next数组
{int c = strlen(a) - 1;                        //c为字符串最后一位 do{int d = c - 1;                            //d为字符串倒数第二位 for(;;){while(d >= 0&&a[c] != a[d])          //判断a[d]=a[c],不然就d--,再次判断,直至a[d]=a[c]或d<0 {d--;}if(d >= 0)                          //d>=0说明a[d]=a[c] {char e[d+2],f[d+2];             //用于比较字符串 //strncpy用来指定长度的字符串copy strncpy(e,&a[0],sizeof(e)-1);   //将a[0]到a[d]复制到e中 strncpy(f,&a[c-d],sizeof(f)-1); //将a[c-d]到a[c]复制到e中 e[d+1] = f[d+1] = '\0';         if(!strcmp(&e[0],&f[0]))        //如果f和e相同,说明匹配成功,令b[c]=d {b[c] = d;//存储的数为前后缀相等的长度-1 break; }else                            //否则继续d--,匹配 {d--;}}else                                //若d<0,说明a中没有与a[c]匹配的 {b[c] = -1;      break;  }}c--;}while(c >= 0);                              //匹配直至c<0,即a中全部字符都匹配完成才结束 }void found(char a[],int b[],article art,FILE *w)    //kmp查找
{int number = 0;                                 //number代表计数,用于统计查找到的个数 ROW *q = art.first; //新定义一个行指针,指向文章第一行 for(;q != NULL;q = q->next)//循环遍历所有行   {int n=0,row_number=0;                       //n代表字符匹配个数,row_number代表行计数,用于统计这一行查找到的个数 word *p = q->r.first->next;//新定义一个字母指针,指向首字母 for(;p != NULL;p = p->next)//循环遍历每一行的全部字符 {if(p->letter == a[n])                   //如果匹配成功,继续下一位匹配 {n++;}else if(n == 0)                         //若匹配不成功,且匹配的是头一个字符,则继续匹配 {continue;}else if(b[n-1] == -1)                   //若预处理中发现不可拖动窗口,则直接继续匹配头一个字符 {n = 0; }else{for(n = b[n-1] + 1;n != 1;n = b[n-1] + 1)     //拖动窗口再次进行比较 {if(p->letter == a[n])                      //匹配成功,继续下一个匹配 {n++;break;}}if(b[n] == -1)                                 //匹配不成功,继续从头一个字符匹配 {n = 0; }}if(n > (strlen(a) - 1))         //全部字符匹配成功,计数加一,行计数加一 ,继续从头字符开始匹配 {number++;row_number++;n=0;}}if(row_number > 0)            //行计数大于0,即这一行有至少一个要查找的单词,则输出 {fprintf(w,"第%d行有%d个\n",q->r.first->letter,row_number);}}fprintf(w,"共计有%d个。\n",number);
}
  • 文学研究助手
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include"文章结构链表.h"
#include"KMP算法匹配.h"
#define size 100               //查找单词的大小 int main()
{FILE *r,*w;//创建文件指针 printf("请将文章放入文件‘英文小说.txt’中(放好请按ENTER键继续)");getchar();if((r = fopen("英文小说.txt","rt")) == NULL){exit(-1); }if((w = fopen("统计词汇的结果.txt","w")) == NULL){exit(-1);}article english;         //english代表英语文章 create_article(&english);//初始化文章 char ch;for(;(fscanf(r,"%c",&ch)) != EOF;){if(ch != '\n')        //添加字母 {add_word(&(english.last->r),ch);}else                 //添加行 {add_row(&english);}}printf("请输入要统计单词的个数:");int number;scanf("%d",&number);
//  getchar();char search[size];           //search代表查找的单词 int result[size];            //result代表预处理结果int next[size];               //next代表用kmp算法预处理结果 int n = 0;//用于for循环          for(;n < number;n++){memset(search,0,sizeof(search));//初始归0 memset(result,0,sizeof(result));//初始归0 printf("请输入第%d个单词:",n+1);scanf("%s",&search[0]);pretreatment(search,result);//预处理 fprintf(w,"第%d个单词%s统计结果:\n",n+1,search); //输出到文件中 found(search,result,english,w); }printf("查找结果放在文件“统计词汇的结果.txt”中");return 0;
}

4.相关文件

  • 英文小说.txt:

China is stepping up efforts to strengthen data security, especially that to be provided overseas, by legislation to better regulate data processing and safeguard State and personal information security.
The Cyberspace Administration of China, the country’s top internet watchdog, unveiled on Wednesday a draft regulation on managing data related to automobiles, to intensify the protection of personal and other crucial data generated on the Chinese mainland.
The draft applies to operators that design, produce, sell, maintain the service of and manage automobiles on the mainland, when they collect, analyze, store, transmit, inquire about, use and delete personal information and key data.
It stipulates that individuals must agree to the collection of their personal data, and personal information or key data should be stored on the Chinese mainland. Data that is to be provided offshore must receive and pass data exit safety assessments by the nation’s cyberspace authorities.
When operators offer personal information or key data abroad, they will need to take effective measures to clarify and supervise that receivers’ use of the data is in accordance with the purpose, scope and manner agreed to by the two sides, in order to ensure data security, according to the draft regulation.
The administration released the full text of the draft regulation online for public advice before June 11. On Wednesday night, US car manufacturer Tesla said in a statement regarding the draft regulation on Sina Weibo, China’s equivalent of Twitter, that it supports and answers the call to have a more regulated industry, and “the public is welcome to offer suggestions to the authorities”.
The latest draft follows an earlier draft law on data security that was submitted to the Standing Committee of the 13th National People’s Congress, China’s top legislature, for a second review in late April. The draft law highlighted the security of outbound data while aiming to promote the development of the data sector.
The draft law specifies that those who privately provide domestic data to judicial or law enforcement agencies overseas may face a fine of up to 1 million yuan ($155,000), and it tightens management of operators trying to take data collected or generated on the mainland to overseas areas.
Besides operators of critical information infrastructure, more data processors, including those of enterprises and data analysis centers, will also face stricter management if they produce or collect data on the mainland, according to the new draft law.
“In other words, the scope of outbound data security management in the latest draft law has been expanded,” said Zhang Tao, a lawyer at Beijing Huaxun Law Offices who specializes in the sector.
“The move is necessary, as the aim of the legislation is to ensure data activities are safe in each step,” he said, adding that security is the foundation of data use and development.
How to keep a balance between ensuring data security while promoting the sound development of the sector has become a hot topic in China, as the country has seen a rapid gowth of big data and data flow in recent years.
Liu Yaohua, a researcher at the China Academy of Information and Communications Technology, published an article in China Economic Weekly in April, in which he said China urgently needed to improve rules on cross-border data flow, as the data sector is booming and many new challenges have surfaced.
The article cited a survey by the Washington-based Brookings Institution, which found that between 2009 and 2018, cross-border data flow contributed about 10 percent to global GDP growth, and the contribution could exceed $11 trillion by 2025. It also noted that the United States, the European Union and other countries or regions have made different cross-border data flow policies based on their own security and economic growth situations.
Liu said a series of high-level policies and rules on cross-border data flow have been implemented at the national, industrial and enterprise levels in China since the Chinese Cybersecurity Law took effect in 2017. He also said China should ensure that data will flow in a legal and orderly manner.
Li Guangqian, a researcher at the Development Research Center of the State Council, said that at present, countries have different attitudes toward cross-border data flow, but he believes that protecting personal information and key data for a country is as important as promoting the development of the data industry.
“China should deal with the cross-border data flow from the perspective of compliance, and formulate relevant rules in line with our own national conditions,” he was quoted as saying by the Financial News in April.

文学研究助手(设计性实验)相关推荐

  1. c语言文学研究助手报告,文学研究助手数据结构报告.doc

    文学研究助手数据结构报告 学号 武汉理工大学华夏学院 课 程 设 计 课程名称 数据结构 题 目 文学研究助手 专 业 班 级 姓 名 __ _ _____ 成 绩 _________________ ...

  2. C++数据结构课程设计——文学研究助手

    设计任务与目标 [问题描述] 文学研究人员需要统计某篇英文小说中某些形容词的出现次数和位置.试写一个 实现这一目标的文字统计系统,称为"文学研究助手". [基本要求] 英文小说存放 ...

  3. 英文文学研究助手(Python)

    Python程序设计实验一(英文文学研究助手) 功能要求及说明: 结果展示 测试文本 测试结果截图 代码 功能要求及说明: (1) 建立文本文件存储一篇英文文小说片段,每个单词不包含空格,且不跨行: ...

  4. c语言文学研究助手报告,数据结构文学研究助手.doc

    数据结构文学研究助手 目 录 一.[实验目的]3 二.[问题描述]3 三.[基本要求]3 四.[实验环境]3 五.[测试数据及其结果]3 六.[实验源代码]5 一.[实验目的] 本次实习的主要目的是熟 ...

  5. 用java实现文学研究助手_数据结构文学研究助手 C语言代码实现(带源码+解析)...

    文学研究人员需要统计某篇英文小说中某些形容词的出现次数和位置.一个实现这一目标的文字统计系统,称为"文学研究助手". 假设英文小说存放在一个文本文件中,每个单词不包含空格且不跨行, ...

  6. 用C语言编程实现矩形波信号,信号与系统综合设计性实验

    信号与系统综合设计性实验 傅立叶变换性质 实验设备 硬件 电脑软件 MATLAB 实验目的 掌握MATLAB的基本使用方法 掌握MATLAB环境下信号表示及产生方法 掌握MATLAB环境下傅立叶变换方 ...

  7. 计算机组成原理设计性实验,《计算机组成原理》设计性实验报告.doc

    <计算机组成原理>设计性实验报告 华北科技学院计算机学院设计性实验 实 验 报 告 课程名称 计算机组成原理B 实验学期 2013 至 2014 学年 第 一 学期 学生所在院部 计算机学 ...

  8. 大物设计性实验:电容、电感量的测量

    这是最后一次大物实验,仅以此文作为纪念. 下面是华南某大学的设计性实验: 一. 实验内容和要求 1.根据实验室所提供的仪器拟定测量电容量.电感量的实验电路.各构思3种以上的测量方法,写出实验步骤及运算 ...

  9. 【操作系统】内存管理设计性实验报告

    操作系统#内存管理设计性实验报告 正文 一. 实验目的 1.通过本次试验体会操作系统中内存的分配模式: 2.掌握内存分配的方法(首次适应(FF),最佳适应(BF),最差适应(WF)): 3.学会进程的 ...

最新文章

  1. GNU make manual 翻译(六十九)
  2. SQL自定义函数split分隔字符串
  3. 网易技术干货 | 云信移动端音视频UI自动化测试实践
  4. linux百度云备份文件夹,Linux环境下载百度网盘文件
  5. xpath 取标签下所有文字内容_GNE 预处理技术——如何移除特定标签但是保留文字到父标签...
  6. 指令include和动作include的区别
  7. 方法用于ThinkPHP3.1快速入门连贯操作
  8. Tiled编辑器不能打开.tmx文件的问题
  9. 扒一扒开源世界有哪些licenses?
  10. IPSEC是如何穿越NAT的
  11. DataGridView突出
  12. 韩顺平细说jsp购物车项目--用户登录及验证
  13. 零起点学习Linux系列培训视频-寒冰作品
  14. Unity 基础资源知识汇总学习
  15. python访问纯真IP数据库
  16. os+rom+android+6.0+n9005,三星S8+官方韩版安卓9固件rom系统线刷升级包:G955NKSU3DSG5
  17. 08Ansible jinjia2模板的使用和管理大项目
  18. JavaScript 之 调用outlook发邮件功能mailto(附带换行问题)
  19. MySQL之binlog
  20. 华为视频终端默认的Web页面用户名和密码是多少

热门文章

  1. 借助Python分析经济
  2. 计算机老师的寄 语,计算机专业老师毕业赠言
  3. 洪九果品上市:年营收百亿市值187亿港元 阿里是股东
  4. 毕业设计 基于B2C的网上拍卖系统设计与实现
  5. 历代华为Mate系列主要参数对比,更新于2020年11月
  6. 使用Spring实现Redis的发布/订阅功能
  7. 对tabcontrol控件增强,添加关闭按钮功能、呼吸灯标签闪烁功能、类QQ消息数量标签提示TIP
  8. 10 条关于 2018 年软件开发的预测,不仅仅是区块链……
  9. 微信公众号开发整理(一)所有微信资料整理参考慕课网学习而得
  10. Qt-5-and-OpenCV-4-Computer-Vision-Projects 学习笔记 - 检测人脸