#define_CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>structNode{int data;structNode* next;};intmain(){structNode* headA =(structNode*)malloc(sizeof(structNode));structNode* headB =(structNode*)malloc(sizeof(structNode));
headA->next =NULL;
headB->next =NULL;structNode* temp;int i;int countA=0,countB=0,countC=0;// 链表A
temp=headA;while(1){scanf("%d",&i);if(i==-1){
temp=temp->next;break;}
countA++;structNode* p =(structNode*)malloc(sizeof(structNode));
p->data=i;
p->next=NULL;
temp->next=p;
temp=p;}// 链表B
temp=headB;while(1){scanf("%d",&i);if(i==-1){
temp=temp->next;break;}
countB++;structNode* p =(structNode*)malloc(sizeof(structNode));
p->data=i;
p->next=NULL;
temp->next=p;
temp=p;}if(countA<countB){printf("ListB is not the sub sequence of ListA.");return0;}structNode*pA,*pB;
temp=headA->next;//记录链表A 开始比较的点while(1){
countC=0;
pA=temp;
pB=headB->next;while(1){if(pA==NULL||pB==NULL){if(countC==countB)printf("ListB is the sub sequence of ListA.");elseprintf("ListB is not the sub sequence of ListA.");return0;}elseif(pA->data!=pB->data)break;elseif(pA->data==pB->data){
countC++;//相同元素的个数
pA=pA->next;
pB=pB->next;}if(countC==countB){printf("ListB is the sub sequence of ListA.");return0;}}
temp=temp->next;}}//5 4 3 2 1 -1//3 2 1 -1