1964: Problem G 填空写注释(综合10分)
题目描述
给你一段可运行的代码,请你补上注释。一处2分共10分 .
#include<stdio.h>
#include<stdlib.h>
int max;
struct Point{//1从2到2之间代码的目的与作用
int x;
int y;
int dis;//dis=x2+y2
struct Point *next;
} *head,*p,*q;//2
int main(int argc, char *argv[]) {
struct Point *head;//这是什么类型的变量,用途是什么
int n;
struct Point *creat(int n);//此行的作用
void out(struct Point *head);
scanf("%d",&n);
head = creat(n);
printf("最远的点是:\n");
out(head);
return 0;//此行的目的
}
struct Point *creat(int n){//这个函数的功能是什么
int i;
q = (struct Point *)malloc(sizeof(struct Point));
scanf("%d %d",&q->x,&q->y);
q->dis = q->x*q->x+q->y*q->y;
p = head = q;
for(i=1;i<n;i++)
{
q = (struct Point *)malloc(sizeof(struct Point));
scanf("%d %d",&q->x,&q->y);
q->dis = q->x*q->x+q->y*q->y;
if(q->dis > max)
{
max = q->dis;
}
p->next = q;
p = p->next;
}
p->next = NULL;
return head;
}
void out(struct Point *head){//请写上链表输出的步骤,可在下面加注释
struct Point *q = head;
while(q!=NULL)
{
if(q->dis==max)
printf("(%d,%d) ",q->x,q->y);
q = q->next;
}
}
输入
见样例。
输出
见样例。
样例输入 复制
6
1 2 5 0 0 5 3 4 2 2 -1 -2
样例输出 复制
最远的点是:
(5,0) (0,5) (3,4)