目录
2009年统考
2012年统考
2015年统考
2019年统考
2009年统考
#include <iostream>
typedef struct node{
int data;
node* next;
}node,*list;
list Init()
{
list head=(list) malloc(sizeof (node));
head->next= nullptr;
head->data=-1;
return head;
}
list Buynewnode(int x)
{
list tmp=new node;
tmp->next= nullptr;
tmp->data=x;
return tmp;
}
int find_last(list head,int x)
{
list p1=head,p2=head;
for(int i=0;i<x;i++)
{
if(p2->next) p2=p2->next;
else {
return 0;
}
}
while(p2)
{
p2=p2->next;
p1=p1->next;
}
printf("%3d",p1->data);
return 1;
}
int main() {
list head=Init();
list pointer=head;
for(int i=0;i<10;i++)
{
pointer=pointer->next= Buynewnode(i+1);
}
for(pointer=head->next;pointer!= nullptr;pointer=pointer->next) {
printf("%3d",pointer->data);
}
puts("");
for(int i=1;i<=13;i++)
{
int record=find_last(head,i);
if(record) printf(" success ");
else printf(" fail ");
}
return 0;
}
2012年统考
#include <iostream>
typedef struct node{
char data;
node* next;
}node,*list;
list Init()
{
list head=(list) malloc(sizeof (node));
head->next= nullptr;
head->data='#';
return head;
}
list Buynewnode(char x)
{
list tmp=new node;
tmp->next= nullptr;
tmp->data=x;
return tmp;
}
list com_start(list h1,list h2)
{
list p1=h1,list,p2=h2;
int n1=0,n2=0;
while(p1) p1=p1->next,n1++;
while(p2) p2=p2->next,n2++;
while(n1>n2) h1=h1->next,n1--;
while(n1<n2) h2=h2->next,n2--;
while(h1)
{
if(h1==h2) return h1;
else{
h1=h1->next;
h2=h2->next;
}
}
return nullptr;
}
int main() {
list head=Init();
list pointer=head,com= nullptr;
char a[9]="loading";
char b[3]="be";
for(int i=0;i<8;i++)
{
pointer=pointer->next= Buynewnode(a[i]);
if(pointer->data=='i') com=pointer;
}
for(pointer=head->next;pointer!= nullptr;pointer=pointer->next) {
printf("%3c",pointer->data);
}
puts("");
list head2=Init();
list pointer2=head2;
for(int i=0;i<2;i++)
{
pointer2=pointer2->next= Buynewnode(b[i]);
}
pointer2->next=com;
for(pointer=head2->next;pointer!= nullptr;pointer=pointer->next) {
printf("%3c",pointer->data);
}
puts("");
list coml= com_start(head,head2);
for(pointer=com;pointer!= nullptr;pointer=pointer->next)
{
printf("%3c",pointer->data);
}
puts("");
return 0;
}
2015年统考
#include <iostream>
#include<time.h>
#include <stdlib.h>
#include<memory.h>
typedef struct node{
int data;
node* next;
}node,*list;
list Init()
{
list head=(list) malloc(sizeof (node));
head->next= nullptr;
head->data=-1;
return head;
}
list Buynewnode(int x)
{
list tmp=new node;
tmp->next= nullptr;
tmp->data=x;
return tmp;
}
void del_abs_com(list head,int n)
{
int *record= (int *) malloc(sizeof (int)*(n+1));
memset(record,0,sizeof (int)*(n+1));
list pointer=head;
while(pointer->next)
{
if(record[abs(pointer->next->data)]){
list tmp=pointer->next;
pointer->next=pointer->next->next;
free(tmp);
}else{
record[abs(pointer->next->data)]++;
pointer=pointer->next;
}
}
}
int main() {
list head=Init();
list pointer=head;
srand(time(nullptr));
for(int i=0;i<10;i++)
{
pointer=pointer->next= Buynewnode(rand()%10-5);
}
for(pointer=head->next;pointer!= nullptr;pointer=pointer->next) {
printf("%5d",pointer->data);
}
puts("");
del_abs_com(head,5);
for(pointer=head->next;pointer!= nullptr;pointer=pointer->next) {
printf("%5d",pointer->data);
}
puts("");
return 0;
}
2019年统考
#include <iostream>
typedef struct node{
int data;
struct node* next;
}node,*list;
list Init()
{
list head=(list) malloc(sizeof (node));
head->next= nullptr;
head->data=-1;
return head;
}
list Buynewnode(int x)
{
list tmp=new node;
tmp->next= nullptr;
tmp->data=x;
return tmp;
}
void print(list head)
{
list pointer=head;
for(pointer=head->next;pointer!= nullptr;pointer=pointer->next) {
printf("%3d",pointer->data);
}
puts("");
}
void split_line(list head)
{
list p1=head,p2=head;
int n=-1;//头结点不算在计算的个数内,如果长度小于3就直接返回
while(p2)
{
p1=p1->next;
p2=p2->next,n++;
if(p2) p2=p2->next,n++;
else break;
}
if(n<=2) return;
p2=p1->next;
list tmp=p2->next;
p2->next= nullptr,p1->next= nullptr;
while(tmp)
{
list pre=tmp->next;
tmp->next=p2;
p2=tmp;
tmp=pre;
}
p1=head->next;
while(p2)
{
list tmp=p1->next;
p1=p1->next=p2;
p2=p2->next;
p1=p1->next=tmp;
}
}
list create_list(int x)
{
list head=Init();
list pointer=head;
for(int i=0;i<x;i++)
{
pointer=pointer->next= Buynewnode(i+1);
}
return head;
}
void test()
{
for(int i=0;i<10;i++)
{
list head=create_list(i);
print(head);
split_line(head);
print(head);
puts("");
}
}
int main() {
test();
return 0;
}