Files
PAT/html/b1075.html
T

40 lines
1.6 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<h1>1075. 链表元素分类(25)</h1>
<div id="problemContent">
<p>给定一个单链表,请编写程序将链表元素进行分类排列,使得所有负值元素都排在非负值元素的前面,而[0, K]区间内的元素都排在大于K的元素前面。但每一类内部元素的顺序是不能改变的。例如:给定链表为 18→7→-4→0→5→-6→10→11→-2,K为10,则输出应该为 -4→-6→-2→7→0→5→10→18→11。</p>
<p><b>
输入格式:
</b></p>
<p>每个输入包含1个测试用例。每个测试用例第1行给出:第1个结点的地址;结点总个数,即正整数N (&lt;= 10<sup>5</sup>);以及正整数K (&lt;=1000)。结点的地址是5位非负整数,NULL地址用-1表示。</p>
<p>接下来有N行,每行格式为:</p>
<p><i>Address Data Next</i></p>
<p>其中<i>Address</i>是结点地址;<i>Data</i>是该结点保存的数据,为[-10<sup>5</sup>, 10<sup>5</sup>]区间内的整数;<i>Next</i>是下一结点的地址。题目保证给出的链表不为空。</p>
<p><b>
输出格式:
</b></p>
<p>对每个测试用例,按链表从头到尾的顺序输出重排后的结果链表,其上每个结点占一行,格式与输入相同。</p>
<b>输入样例:</b><pre>
00100 9 10
23333 10 27777
00000 0 99999
00100 18 12309
68237 -6 23333
33218 -4 00000
48652 -2 -1
99999 5 68237
27777 11 48652
12309 7 33218
</pre>
<b>输出样例:</b><pre>
33218 -4 68237
68237 -6 48652
48652 -2 12309
12309 7 00000
00000 0 99999
99999 5 23333
23333 10 00100
00100 18 27777
27777 11 -1
</pre>
</div>