求一道题目的算法伪代码A company handles international messages. Currently, the messages are printed ontoa continuous strip of paper which is cut up and pasted onto sheets of paper for delivery.The owner of the company has decided to automa
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/28 03:43:20
求一道题目的算法伪代码A company handles international messages. Currently, the messages are printed ontoa continuous strip of paper which is cut up and pasted onto sheets of paper for delivery.The owner of the company has decided to automa
求一道题目的算法伪代码
A company handles international messages. Currently, the messages are printed onto
a continuous strip of paper which is cut up and pasted onto sheets of paper for delivery.
The owner of the company has decided to automate this process, printing the messages
directly onto sheets of paper. Your task is to develop a pseudo code algorithm to achieve
this purpose. The owner can tell you the following things:
1. The incoming message arrives in the form of a series of one or more blocks of data.
2. The outgoing message will be produces as a series of pages.
3. Each page may contain up to 60 lines.
4. Each line can contain up to 100 characters.
5. Words may not be split across lines.
6. As many words as possible must be fitted onto each line.
7. Each message must start on a new page.
8. You have 3 sub-programs already provided.
a. getBlock which fills an array with the next incoming block of text.
b. putLine which prints the next line of text onto the page.
c. putPage which ejects the current page and starts the next.
9. Each block can hold up to 500 characters.
10. The end of a block is designated by the character ‘#’.
11. The 500 character limit includes the end of block character.
12. The end of a message is designated by an empty block.
13. An empty block consists of a one-character long block containing ‘#’.
14. The character ‘#’ only appears as the end of a block.
15. A message consists of a series of words.
16. Words are separated by spaces, sequences of one or more occurrences of the ‘ ’
character.
17. The alphabet consists of the capital letters ‘A’ to ‘Z’ , the space ‘ ’ and the hash ‘#’.
18. Numbers and punctuation are spelled out
19. On arrival, the first word of a message may have spaces before it.
20. On arrival, the last word of a message may be followed by spaces.
21. On Arrival, there may be multiple spaces between words.
22. Blocks may consist entirely of spaces.
23. On arrival, words may be split between blocks.
24. On output there must be no space before the first word on any line
25. On output there will be no more than 1 space between words
26.No word in the message will be longer than 100 characters.
You should create a solution in which the Algorithm is clear and easily tested.
Use the principles of top-down design and modular programming.
Select one of the sub-algorithms you create and provide a detailed flow chart for it following
the rules and conventions taught in class.
给出了26个条件,让写伪代码,不要求有全部答案,有个大概思路就好
求一道题目的算法伪代码A company handles international messages. Currently, the messages are printed ontoa continuous strip of paper which is cut up and pasted onto sheets of paper for delivery.The owner of the company has decided to automa
这道题我包了,其他人速速退散.明天告诉你答案.当然只是思路,我从来都是给人渔,而不是鱼.
我睡好了,现在来回答你的问题,感谢楼上的支持!顺便感慨一下老外出的题就是高明,我上学时候没有这么好的题来引导学生.
先看题目,不要太关注于细节,可以用一句话概括这题,那就是把一系列的block转化成message,message由多个page组成.这就是一个程序的高度抽象,以此为准一步一步实现细节.
第二步看你有什么东西可以利用,那就是第8条提到的3个子程序,你要自己写一些程序来调用这3个子程序来实现目标.
先写得到多个block并转成一个message的方法,然后不停调用此方法就行了.
分两步,一是得到构成一个message的多个block,很简单的,伪代码如下:
while(true)
{
getBlock;
if (lastBlock.text == "#")
{
break;//如果刚刚得到的block只包含一个#号,说明是一个message的结束.退出循环,数组中包含的就是构成一个message的所有block
}
}
二是根据这些block,构造message.先把block文本的开头结尾空格除掉,然后把多个连续空格变成一个空格,这些就自己做吧不会再问.
然后顺序根据把block里的每一个单词放到一个临时字符串,每当这个字符串够了100个字,就调用putline,如果不够100,看加上下一个够不够,超了就不要下一个,因为一个单词不能换行.每写够60行就调putPage,直到把所有block都用完.