#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
typedef struct st {
char data;
struct st*next;
}NODE,*PNODE;
PNODE creat_list(int length)
{
PNODE pHead=(PNODE)malloc(sizeof(NODE)*1);
pHead->next=NULL;
if(NULL==pHead)
{
printf("动态内存分配失败!程序终止\n");
exit(-1);
}
char val;
PNODE pTail=pHead;
pTail->next=NULL;
for(int j=0;j<length+1;j++)
{
PNODE pNew=(PNODE)malloc(sizeof(NODE)*1);
if(NULL==pNew)
{
printf("动态内存分配失败!程序终止\n");
exit(-1);
}
scanf("%c",&val);
pNew->data=val;
pTail->next=pNew;
pNew->next=NULL;
pTail=pNew;
}
return pHead;
}
//按位查找
void serach_list(PNODE pHead,int len,int i)
{
char val;
int count=1;
if(pHead==NULL)
{
printf("not found\n");
}
else
{
PNODE p=pHead->next;
scanf("%c",&val);
while(p!=NULL)
{
p=p->next;
count++;
}
printf("%d\n",count);
}
}
int main()
{
PNODE pHead=NULL;//初始化头指针
int len,i;
//char val;//存储找到那个字符的值
while(~scanf("%d %d",&len,&i)){
getchar();
pHead=creat_list(len);
serach_list(pHead,len,i);
}
}