//后插的话需要多用一个标记指
#include <iostream>
#include <string>
#include <stdio.h>
using
namespace
std;
struct
Entry
{
string m;
Entry *next;
};
Entry *GetNewEntry(){
string p;
cin>>p;
Entry *newOne=
new
Entry;
//if (p==EOF) return NULL;
newOne->m=p;
newOne->next=NULL;
return
newOne;
}
Entry *BuildList(
int
n)
{
Entry *listHead=NULL;
Entry *p=NULL;
while
(n>0)
{
Entry *newOne=GetNewEntry();
//if(newOne==NULL) break;
//if (n==0) break;
n--;
if
(p==NULL)
{
p=newOne;
listHead=p;
}
else
{
//newOne->next=p;
//p->next=newOne;
//p=p->next;
p->next=newOne;
p=p->next;
}
}
return
listHead;
}
Entry *findk(
int
k,Entry *listHead){
Entry *p,*q;
p=listHead;
q=p;
if
(k==0)
return
NULL;
while
(k>0)
{
q=q->next;
k--;
if
(k>0&&q==NULL&&p!=NULL)
{
return
NULL;
}
}
while
(q!=NULL)
{
p=p->next;
q=q->next;
}
return
p;
}
int
main()
{
int
num,k;
while
(cin>>num>>k)
{
Entry *list=BuildList(num);
Entry *p=findk(k,list);
if
(p!=NULL)
{
cout<<p->m<<endl;
}
else
{
cout<<
"NULL"
<<endl;
}
}
}
/**************************************************************
Problem: 1517
User: 无梦楼主lv
Language: C++
Result: Accepted
Time:290 ms
Memory:5480 kb
****************************************************************/