问我几多愁,恰似正逢考试啥啥不会
为了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循环函数中不可以再次定义尾指针,而头指针的定义需要在循环中出现,我犯这个好多次了。。。。。老记不住。。。死脑筋
#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;
}
这个题和上面一样,太水了,下一个
添加链接描述
#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;
}
#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;
}
没啥意思的题