东北林业大学锐格系统练习题(课后题部分)

问我几多愁,恰似正逢考试啥啥不会

为了C语言考试不拖后腿,决定重新写一下锐格系统的测试题 ,那那那那我这个菜鸟就从最简单的课后题章节开始写吧!
3509题
链表题目
【我自己码的代码如下图,但是but,不符合网管要求,菜鸟的我不知道为啥,跑起来是对的】

#include <stdio.h>
#include <stdlib.h>
//write your code here
typedef struct list{
   int data;
   struct list *next;
};
int main()
{
    //write your code here
    struct list *head;
    int m,temp;
    head=(struct list *)malloc(sizeof(struct list));
    head->next=NULL;
    struct list *tp;
    tp=head;
    while(~scanf("%d",&(temp))&&temp!=-1)
    {   struct list *p;
        p=(struct list *)malloc(sizeof(struct list) );
        p->data=temp;
        p->next=tp->next;
        tp->next=p;
        tp=p;

    }
	tp->next=NULL;
    scanf("%d",&m);
    struct list *pre,*nowp;
    pre=head;
    while(pre->next!=NULL)
    {  nowp=pre->next;
        if(nowp->data==m)
        {
           pre->next=nowp->next;

        }

        pre=pre->next;

    }
    struct list *find;
    find=head->next;
    while(find!=NULL)
    {
        printf("%d ",find->data);
        find=find->next;
    }
	return 0;
}

【同学大佬码的他的是对的,我寻思着没啥区别】

#include <stdio.h>
#include <stdlib.h>
//write your code here
typedef struct{
   int data;
   struct List* next;
}List;
int main()
{
    //write your code here
    int temp;
    List *Head,*Rear;
    Head=(List*)malloc(sizeof(List));
    Head->next=NULL;
    Rear=Head;
    while(~scanf("%d",&temp)&&temp!=-1){
        List *node;
        node=(List*)malloc(sizeof(List));
        node->data=temp;
        Rear->next=node;
        Rear=node;
	}
	Rear->next=NULL;
	//以上为链表的创建
	int target;
	scanf("%d",&target);
	List *find=Head;
	while(find->next!=NULL){
        List *now=find->next;
        if(now->data==target){
            find->next=now->next;
            free(now);
        }
        find=find->next;
	}
	//以下为链表的输出
    find=Head->next;
    while(find!=NULL){
        find->next==NULL?printf("%d\n",find->data):printf("%d ",find->data);
        find=find->next;
    }
	return 0;
}

反思

本次这个题,我遇到无法输入的问题,就是那个m输入不出来,其原因是在建立链表的while循环函数中不可以再次定义尾指针,而头指针的定义需要在循环中出现,我犯这个好多次了。。。。。老记不住。。。死脑筋

3054题
最简单的头插法考察

#include <stdio.h>
#include <stdlib.h>
//write your code here
typedef struct list{
   int data;
   struct list* next;
};

int main()
{
    //write your code here

	struct list *head;
	head=(struct list *)malloc(sizeof(struct list) );
	head->next=NULL;//建立有头结点
    int temp;
    while(~scanf("%d",&temp)&&temp!=-1)
    {
        struct list *p;
        p=(struct list *)malloc(sizeof(struct list));
        p->data=temp;
        p->next=head->next;
        head->next=p;

    }
	//以上为链表的创建
	//以下为链表的输出
   struct list *find=head->next;
    while(find!=NULL){
        printf("%d",find->data);
        find=find->next;
    }
	return 0;
}

想法:这个题太简单了,期末考试如果出这样的,我能从梦里笑死,哈哈哈哈哈
3053
简单的有头尾插法

#include <stdio.h>
#include <stdlib.h>
//write your code here
typedef struct list{
   int data;
   struct list* next;
};

int main()
{
    //write your code here

	struct list *head;
	head=(struct list *)malloc(sizeof(struct list) );
	head->next=NULL;//建立有头结点
    int temp;
    struct list *tp;
    tp=head;
    while(~scanf("%d",&temp)&&temp!=-1)
    {
        struct list *p;
        p=(struct list *)malloc(sizeof(struct list));
        p->data=temp;
        p->next=tp->next;
        tp->next=p;
        tp=p;
    }
	//以上为链表的创建
	//以下为链表的输出
   struct list *find=head->next;
    while(find!=NULL)
    {
        printf("%d",find->data);
        find=find->next;
    }
	return 0;
}

这个题和上面一样,太水了,下一个
添加链接描述
3454

#include <stdio.h>
#include <stdlib.h>
int cmp(const void *p1, const void *p2);
int contain(int *array, int size, int value);
int main()
{       int *A, *B, *result;
        int sizeA, sizeB,sizeResult=0;
        scanf("%d",&sizeA);
        A = (int *)malloc(sizeof(int) * sizeA);
        int i, j;
        for (i = 0; i < sizeA; ++i) 
        {   scanf("%d",A + i); }
        scanf("%d", &sizeB);
        B = (int *)malloc(sizeof(int)* sizeB);
        result=(int *)malloc(sizeof(int) * (sizeA + sizeB));
        for (i=0;i<sizeB; ++i) 
        {  scanf("%d",B+i);  }
        // write your code here
        qsort(result, sizeResult, sizeof(int), cmp);
        for (i = 0; i < sizeResult; ++i) 
        {  printf("%d ", result[i]);  }
        printf("\n");
         return 0;
}
int contain(int *array, int size, int value) 
{
        while (size >= 0)
         {if (array[--size] == value) 
                    {
                        return 1;
                    }
                    }
  return 0;
}
int cmp(const void *p1, const void *p2)
{ return *(int *)p1 - *(int *)p2;
}

2803
在这里插入图片描述

#include <stdio.h>
int main()
 {
    struct student
    {
    	int num;
		char name;
	};
	struct student person1;
	struct student *p;
    //write your own codes
	p=&person1;
	p->num=20001;
	p->name='A';
	printf("%d %c",p->num,p->name);
	return 0;
}

没啥意思的题

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值