# 程序设计能力实训

1259. 链表查询

// * Definition of the structure *

typedef struct Node

{ int value;

struct Node *next;

} NODE;

//** Specification of FindLastNthNode ****

NODE FindLastNthNode(NODE h,int n);

/* PreCondition:

h is a head pointer of a linked-list, n is an integer

PostCondition:

return the pointer of the last nth node in the linked-list,

or 0 if such node can’t be found

*/

Input
3
1100 2 5 2
1 2 3 4
4 3 2 1
Output
case #0:
2:2 2
case #1:
NONE:2 1
case #2:
1:1 0 1

### 提示

// ********** Specification of struct Node **********
typedef struct Node
{ int value;
struct Node *next;
}NODE;
/*/////////////////////////////////////////////////////*/
NODE *FindLastNthNode(NODE *h,int n)
/* PreCondition:
h is a head pointer of a linked-list, n is an integer
PostCondition:
return the pointer of the last nth node in the linked-list,
or 0 if such node can’t be found
*/
}
/*/////////////////////////////////////////////////////*/
/***************************************************************/
/*                                                             */
/*  DON'T MODIFY following code anyway!                        */
/*                                                             */
/***************************************************************/
#include <stdio.h>
#include <malloc.h>
static unsigned long next = 1;
int RND()
{ next = next * 1103515245 + 12345;
return (unsigned) (next/65536) % 32768;
}
void SETSEED(unsigned seed) { next = seed; }
void solve()
scanf("%d%d%d%d",&s,&t,&m,&n); SETSEED(s);
for (i=0;i<t;i++)
{ p=(NODE*)malloc(sizeof(NODE));
p->value=RND()%m; p->next=0;
}
else printf("NONE:");
n=0;
if (t<100||t>100 && n<100)
{ printf("%d",p->value);  if (head) printf(" ");}
n++; free(p);
}
printf("\\n");
}
int main()
{  int i,t;  scanf("%d\\n",&t);
for (i=0;i<t;i++) { printf("case #%d:\\n",i); solve(); }
return 0;
}