首页 > 其他分享 >曼哈顿距离

曼哈顿距离

时间:2022-11-27 20:31:17浏览次数:40  
标签:abs 曼哈顿 距离 int cy cx printf include

利用曼哈顿距离来打印菱形。

#define _CRT_SECURE_NO_WARNINGS 1

#include <cstdio>

#include <iostream>

int main()
{
int n;
scanf("%d", &n); //n为奇数
int cx = n / 2, cy = n / 2; //中心点的坐标
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (abs(j - cx) + abs(i - cy) <= n / 2) printf("*");
else printf(" ");
}
printf("\n");
}
return 0;
}

曼哈顿距离_曼哈顿距离

曼哈顿距离_ios_02

标签:abs,曼哈顿,距离,int,cy,cx,printf,include
From: https://blog.51cto.com/u_15815053/5890297

相关文章