首页 > > 详细

ASCII讲解、辅导C/C++编程、讲解C/C++语言、辅导strcmp 辅导Python编程|解析Haskell程序

Problem I: Sort of Continued Lines
Your task is to write a C program named I.c according to the specifications below.
You should be familiar with the program sort that can sort lines of a textual file in various ways
using the keys. A simple sort will just sort lines alphabetically, or to be more precise in the ASCII
order using the characters in the line and using the lexicographic order.
In some situations, we may want to keep several lines together and we do not want to break them in
sorting. For example we can indicate that a line continues into the next line by using the backslash
character at the very end of the line. Your task is to write a sorting program that sorts lines in such
way that the continued lines are not broken. The continued lines should be sorted and compared to
each other as long strings using the function strcmp.
Since there is not specified limit on the number of lines or the length of one line, it is recommended
that you use malloc and realloc functions to allocate for each continued line exactly as much
memory as required. You can read all continued lines into a linked list, then sort the list, and print
them from the list.
Input
The standard input includes an arbitrary text. There are no specified limitations to the number of
of lines or the length of lines.
Output
Your program must keep continued lines in a group, where any line continues to the next line
if there is the backslash character at the very end of the line, and the program must printed the
continued lines in a sorted order. Of course, the continued line can be mixed with single lines that
are not part of any group.
Sample input and output are given below:
Sample Input Sample Output
This is first group of lines AAAA\ Another continued DDDD\
AAAA and continued BBB\ DDD line
BBB and continued CCC\ Another line
CCC line B line EEEE \
Another line EEEE and so on
Another continued DDDD\ This is first group of lines AAAA\
DDD line AAAA and continued BBB\
B line EEEE \ BBB and continued CCC\
EEEE and so on CCC lineSample Output, with
visualized whitespace
Another continued DDDD\\n
DDD line\n
Another line\n
B line EEEE \\n
EEEE and so on\n
This is first group of lines AAAA\\n
AAAA and continued BBB\\n
BBB and continued CCC\\n
CCC line\n
Note: is a space, and \n is a newline character.

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!