Home > Back-end >  PAT a problem. There are two test points hard, just do not know where the problem is...
PAT a problem. There are two test points hard, just do not know where the problem is...

Time:10-05

Title:
1074. The Reversing Linked List (25)
Time limit
400 ms
Memory limit
65536 kB
The code length limit
16000 B
Sentence topic program
Standard
The author
CHEN, make
Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elements on l. For example, Given the L being 1-2-3-4-5-6, if K=3, then you must output the 3-2-1-6-5 -> 4; If K=4, you must output 4-3-2-1-5-6.
Input Specification:
Each input file contains one test case. For Each case, the first line contains the address of the first node, a positive N (& lt;=105) which is the total number of nodes, and a positive K (& lt;=N) which is the length of the sublist to be reversed. The address of a node is a 5 - digit nonnegative integer, and NULL is represented by - 1.
Then N lines follow, each describes a node in the format:
The Address Data Next
Where the Address is the position of the node, the Data is an integer, and the Next is the position of the Next node.
The Output Specification:
For each case, the output of the resulting ordered linked list, each node occupies a line, and is printed in the same format as in the input.
The Sample Input:
00100 June 4
00000 4 99999
00100 1 12309
68237 6-1
33218 3 00000
99999 5 68237
12309 2 33218
The Sample Output:
00000 4 33218
33218 3 12309
12309 2 00100
00100 1 99999
99999 5 68237
68237 6-1

Test results:


 # include 
#include
using namespace std;

The class Node
{
Public:
Int thisindex=1;
Int next=1;
Int the pre=1;
Int val.
};

Int main ()
{
The Node * link=new Node [100005].
Int head, n, k;
Cin & gt;> Head & gt;> N & gt;> k;
int i;
for (i=0; i Int index, val, next;
Cin & gt;> The index & gt;> Val & gt;> next;
The link [index] thisindex=index;
The link [index]. Val=val;
The link [index]. Next=next;
The link [next]. Pre=index;
}
Int kindex=head;
While (k - 1) {
Kindex=link [kindex] next;
K -;
}
Int p=kindex;
While (p!=1) {
cout If (link [p]. Pre==1) {
If (link) [r]. Kindex next==1) {
cout }
The else {
cout }
}
The else {
cout }
P=link [p]. Pre;
}
P=link [kindex] next;
While (p!=1) {
cout If (link [p]. Next==1) {
cout }
The else {
cout }
P=link [p]. Next;
}

system("pause");
return 0;
}

CodePudding user response:

Boundary condition
Input and output format
.

CodePudding user response:

I am also the two test points but,,,

CodePudding user response:

Hello, pat test data points where there is excuse me

CodePudding user response:

Are all in English, look not to understand ah,,,,,,,,,,,,,,,,,

CodePudding user response:

The question of the problem is that every k bit flip once, not k bit flip only once before, the first example is given in the question 3 - & gt; 2 - & gt; 1 - & gt; 6 - & gt; 5 - & gt; Instead of 3-4 & gt; 2 - & gt; 1 - & gt; 4 - & gt; 5 - & gt; 6

CodePudding user response:

Upstairs positive solution, eldest brother, you even the title given in the test the sample before... You try
00100 June 3
00000 4 99999
00100 1 12309
68237 6-1
33218 3 00000
99999 5 68237
12309 2 33218
  • Related