在程序当中实现的序列号的计算的运算程序,怎么利用C语言代码设计的思想方法来编?

Problem Description
A manufacturer keeps an ordered table of serial numbers by listing in each row of the table a range of serial numbers along with two corresponding pieces of information called the status code and the transfer code. A four-column table stores information about ranges of serial numbers in this order: starting serial number, ending serial number, status code, transfer code. Serial numbers as well as transfer codes are integers from 1 to 2147483647, and status codes are a single upper-case letter. The table is maintained in
increasing order of serial numbers, serial number ranges are never allowed to overlap, and for any given serial number, the table must always accurately represent the most recent data (status code and transfer code) for
that serial number.
Let's say that 100,000 serial numbers are created with a status of "A" and a transfer code of "1". An entry for those serial numbers might look like this:
1 100000 A 1
This is obviously far more efficient than storing 100,000 individual rows all with the same status and transfer codes. The challenge arises when serial numbers within already defined ranges need to be given different
status or transfer codes. For example, if serial number 12345 needs to change to status B, the above table would need to become three separate entries:
1 12344 A 1
12345 12345 B 1
12346 100000 A 1
Now let's change the transfer code of all serial numbers in the range 12000 to 12999 to 2. This gets us:
1 11999 A 1
12000 12344 A 2
12345 12345 B 2
12346 12999 A 2
13000 100000 A 1
Now change all existing serial numbers from 10000 to 100000 to status C and transfer code 2:
1 9999 A 1
10000 100000 C 2
Once created a serial number will never be deleted, but it is possible to have ranges of undefined serial
numbers between ranges of defined ones. To demonstrate, let's now set all serial numbers from 1000000 to
1999999 to status Z and transfer code 99:
1 9999 A 1
10000 100000 C 2
1000000 1999999 Z 99
Finally, the table is always maintained with a minimal number of rows, meaning specifically that there will
never be two adjacent rows in the table where one would suffice. For example, consider the following serial
number table:
1 10 A 1
11 20 A 1
21 30 B 1
The first two rows could actually be represented by a single row, meaning that the table above does not have
a minimal number of rows. The same data represented by a minimal number of rows would look like this:
1 20 A 1
21 30 B 1
The following table, however, because the first two rows have non-matching transfer codes, already contains
the minimal number of rows:
1 10 A 1
11 20 A 2
21 30 B 1
Similarly, the following table cannot be reduced further because the first two rows do not represent a
continuous series of serial numbers:
1 10 A 1
12 20 A 1
21 30 B 1

Input
Each input case begins with a single line that is a character string naming the test case. This string
contains at most 80 characters. The name "END" marks the end of the input. Following this will be 1 to 100
lines of the form "A B S T", where A, B, and T are integers in the range 1 to 231-1, S is an uppercase letter,
and A<=B. These lines are, in the order they are to be applied, the serial number transactions to be recorded,
where A is the start of the serial number range, B is the end of the serial number range, S is the status code,
and T is the transfer code. The list of serial number transactions is terminated by a line containing only a 0
(zero) character.

Output
For each input case, echo the test case name to the output on a line by itself, followed by the resulting minimal-rows serial number table that results after all serial number transactions have been applied.

Sample Input
First Example
1 100000 A 1
12345 12345 B 1
0
And Another
1 100000 A 1
12345 12345 B 1
12000 12999 A 2
12345 12345 B 2
0
Test Case Three
1 100000 A 1
12345 12345 B 1
12000 12999 A 2
12345 12345 B 2
10000 100000 C 2
0
Example Four
1 100000 A 1
12345 12345 B 1
12000 12999 A 2
12345 12345 B 2
10000 100000 C 2
1000000 1999999 Z 99
0
Example 5
1 10 A 1
21 30 B 1
11 20 A 1
0
Example 6
21 30 B 1
1 10 A 1
11 20 A 2
0
Example 7
12 20 A 1
21 30 B 1
1 10 A 1
0
END

Sample Output
First Example
1 12344 A 1
12345 12345 B 1
12346 100000 A 1
And Another
1 11999 A 1
12000 12344 A 2
12345 12345 B 2
12346 12999 A 2
13000 100000 A 1
Test Case Three
1 9999 A 1
10000 100000 C 2
Example Four
1 9999 A 1
10000 100000 C 2
1000000 1999999 Z 99
Example 5
1 20 A 1
21 30 B 1
Example 6
1 10 A 1
11 20 A 2
21 30 B 1
Example 7
1 10 A 1
12 20 A 1
21 30 B 1

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!

相似问题

3
怎么样才能获取唯一的CPU序列号
0
寻找集合的非递减序列的算法,怎么利用C语言程序的设计办法来实现的
2
使用phtread多线程编程程序来生成Fibonacci序列 c/c++
0
真假数的序列的一个判断的算法,怎么用C语言的程序的设计的方式实现
1
如何提取电脑硬盘物理序列号最后2位数字?
0
最终的序列的计算,网格搜索的一个算法,怎么利用C语言的程序的技术实现的
0
单调增长的子序列的一个算法题,要求利用C语言的程序编写的思想来实现怎么做
0
输出序列开头的元素的做法,利用C语言的程序的射击的语言的方式
0
子序列的重复的次数的问题怎么利用C语言的程序的实现的技巧是什么
0
对于给定的N对双胞胎,是否有一个年龄序列的判断,运用C语言的程序的设计的思想去实现的方法
0
序列的删除的一个做法,怎么采用C语言的程序编写的过程实现序列的删除
0
字符串的字符的序列的距离的计算,怎么采用C语言的程序的实现的思路怎么做?
0
C语言解决字符的序列的输出的问题,具体的程序的编写的实现的做法怎么实现?
0
计算最大的子序列的和是多少,怎么利用C语言的程序的编写的思路的实现?
0
计算线性的公式的构成的序列,怎么采用C语言的程序编写的思想的过程
0
序列三元组的除法的算法,怎么采用C程序的的语言的代码的编写的过程去实现的?
0
序列上包含的整数的数列的问题,怎么利用C语言的程序代码的编程技术实现的?
0
置换组合的排序算法问题,怎么利用C程序的代码编写技术实现序列的位置的求解?
0
是否有一个年龄序列,满足特定规律的判断,怎么利用C语言程序编写的技术去用代码的方法来实现?
0
多次的计算的子序列算法问题,怎么采用的C语言程序编写的办法实现的?