联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> C/C++编程C/C++编程

日期:2018-11-28 10:35

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 line

Sample 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.


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp