题目描述

水题,使用结构体表示点坐标
#include<cstdio>
using namespace std;
struct point{
long long x,y;
}first,last,now;
int main(){
int n;
while(scanf("%d",&n)!=EOF){
printf("%d",n);
scanf("%lld%lld",&first.x,&first.y);
now=first;
for(int i=1;i<n;i++){
scanf("%lld%lld",&last.x,&last.y);
printf(" %.6f %.6f",(last.x+now.x)/2.0,(last.y+now.y)/2.0);
now=last;
}
printf(" %.6f %.6f",(last.x+first.x)/2.0,(last.y+first.y)/2.0);
printf("\n");
}
return 0;
}
本文介绍了一段使用 C++ 编写的程序,通过结构体表示点坐标,实现计算 n 个点对连线中点的平均位置。程序通过输入点的坐标,依次计算并输出每个连接点的中点坐标,最后以第一点和最后一点的中点作为结束。
1090

被折叠的 条评论
为什么被折叠?



