c语言压缩文本文件 求解答!写出来再加10分!

c语言压缩文本文件 求解答!写出来再加10分!
48 压缩文本文件
成绩: 5 / 折扣: 0.8

背景:

压缩是一种有效的减小数据量的方法,目前已经被广泛应用于各种类型的信息系统之中。

一种压缩文本文件的方法如下:

1. 原始文本文件中的非字母的字符,直接拷贝到压缩文件中;

2. 原始文件中的词(全部由字母组成),如果是第一次出现,则将该词加入到一个词的列表中,并拷贝到压缩文件中;否则该词不拷贝到压缩文件中,而是将该词在词的列表中的位置拷贝到压缩文件中。
3. 词的列表的起始位置为 1 。 词的定义为文本中由大小写字母组成的最大序列。大写字母和小写字母认为是不同的字母,即 abc 和 Abc 是不同的词。词的例子如下: * x-ray 包括两个词 x 和 ray * mary's 包括两个词 mary 和 s * a c-Dec 包括三个词 a 和 c 和 Dec 编写一个程序,输入为一组字符串,输出为压缩后的文本。

输入:

输入为一段文本,你可以假设输入中不会出现数字、每行的长度不会超过 80 个字符,并且输入文本的大小不会超过 10M。

输出:

压缩后的文本。
测试输入
1.Please, please do it--it would please Mary very,↵
2.very much.↵
3.↵
4.Thanks↵

期待输出
1.Please, please do it--4 would 2 Mary very,↵
2.7 much.↵
3.↵
4.Thanks↵
测试输入1.Background↵
2.↵
3.Given an m by n grid of letters and a list of words, find the location in the↵
4.grid at which the word can be found.↵
5.↵
6.A word matches a straight, uninterrupted line of letters in the grid. A word↵
7.can match the letters in the grid regardless of case (i.e., upper- and↵
8.lowercase letters are to be treated as the same). The matching can be done in↵
9.any of the eight horizontal, vertical, or diagonal directions through the grid.↵
10.↵
11.Input↵
12.↵
13.The input begins with a single positive integer on a line by itself indicating↵
14.the number of cases, followed by a blank line. There is also a blank line↵
15.between each two consecutive cases.↵
16.↵
17.Each case begins with a pair of integers m followed by n on a single line,↵
18.where m, n in decimal notation. The next m lines contain n letters each,↵
19.representing the grid of letters where the words must be found. The letters↵
20.in the grid may be in upper- or lowercase. Following the grid of letters,↵
21.another integer k appears on a line by itself (k). The next k lines of inp↵
期待输出的形式和第一个测试用例一样
m359364173 1年前 已收到1个回答 举报

疯疯癫癫123456 幼苗

共回答了13个问题采纳率:92.3% 举报

可以考虑用一个map 键值对 来存放 的首次出现单词,一个单词对应一个序号
然后一行一行进行读取,对每一行里的字符 只要不是字母 就截取来 和 map、中已有的单词进行比较 重复的 就取出序号代替 不重复的 放进map
这样就好了
你需要一个获取单词的函数 一个压缩单词的函数 一个比较单词的函数
把这3个函数做出来 你的程序 大致就好了
这个 你自己想比较好 和简单其实

1年前

6
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 17 q. 0.492 s. - webmaster@yulucn.com