Description
Andy is fond of old computers. He loves everything about them and he uses emulators of old operating systems on his modern computer. Andy also likes writing programs for them. Recently he has decided to write a text editor for his favorite text-mode operating system. The most difficult task he has got stuck with is document indexing. An index of the document is the lexicographically ordered list of all words occurring in the document with the numbers of pages they occur at. Andy feels that he is not able to write the component of the editor that performs indexing, so he asks you to help. A document is a sequence of paragraphs. Each paragraph consists of one or more lines. Paragraphs are separated from each other with exactly one blank line. First, the document is paginated -- divided into pages. Each page consists of up to n lines. Lines are placed on the page one after another, until n lines are placed. The following correction rules are then applied:
- If the last line on a page is the last line of the paragraph, then the following empty line is skipped, i.e. it is not placed on any page. Therefore, the page never starts with a blank line.
- If the last line on a page is the first line of a paragraph that contains more than one line (so called orphan line), then it is moved to the next page.
- If the last line on a page is the next-to-last line of a paragraph that contains more than three lines, then this line is moved to the next page (otherwise, the last line of the paragraph would be alone on the page -- so called widow line).
- If the last line on a page is the next-to-last line of a paragraph that contains exactly two or three lines, then the whole paragraph is moved to the next page (so we have neither orphan, nor widow lines).
Input
The first line of the input contains n (4 <= n <= 100). The rest of the input file contains the document to be indexed. The size of the input does not exceed 20 000 bytes. The line is considered blank if it is completely empty. No line contains leading or trailing spaces. The document does not contain two consecutive blank lines. The first line of the document is not blank. The length of each line of the document does not exceed 200 characters.
Output
Print all words that occur in the given document. Words must be printed in the lexicographical order, one word on a line. After each word print one space followed by the list of pages it occurs at, formatted as described in problem statement. Use capital letters in output.
题目大意:模拟一些段落的书页分配。除了一段只有一行的,不要让任何行单独在一页的最上面和最下面。
思路:模拟。注意如果像我这么做一段一段读的话要开大内存,之前开了1000行结果WA了无数次>_<。我的做法相当暴力啊o(╯□╰)o
代码(922MS):
1 #include2 #include 3 #include 4 #include 5 #include 6 #include 7 #include