Problem Description
在美丽的HDU,有一名大三的同学,他的速度是众所周知的,跑100米仅仅用了2秒47,在他跑步过程中会留下残影的哎,大家很想知道他是谁了吧,他叫仙人球,既然名字这样了,于是他的思想是单一的,他总是喜欢从一点出发,经过3次转折(每次向右转90°),回到出发点,而且呢,他每次转折前总是跑相同长度的路程,所以很多人都想知道如果用‘1’算他跑步出发的第一个残影的话,那么回到起点的时候,他的残影是怎么样的呢?
Input
测试数据有多行,每一行为一个数N(1<=N<=10)(以0结尾,0不做处理),即仙人球在没有回到起点的时候,跑过留下N个残影后突然90°右转。
Output
每组测试数据输出一个结果,并且每个残影的计数位长度为3个字符长度。(当然N等于1的话,它的结果也是占用3个字符位置的)
Sample Input
4
Sample Output
1 2 3 4
12 5
11 6
10 9 8 7
AC代码:
#include<iostream>
#include<string>
using namespace std;
int main() {
int n;
while (scanf_s("%d", &n) != EOF) {
if (n == 0) {
break;
}
if (n == 1) {
printf(" 1 ");
continue;
}
int m = 4 * (n - 1); //点的个数
int s = n + 1;
//打印第一行
for (int i = 1; i <= n; i++) {
printf("%3d", i);
}
printf("\n");
//打印2~n-1行
for (int i = 0; i < n-2; i++) {
for (int j = 0; j < n; j++) {
if (j == 0) {
printf("%3d", m);
m--;
}
else if (j == n - 1) {
printf("%3d", s);
s++;
}
else {
printf(" ");
}
}
printf("\n");
}
//打印第n行
int d = 3 * n - 2;
for (int i = 0; i < n; i++) {
printf("%3d", d);
d--;
}
printf("\n");
}
return 0;
}