传送门
我们先分析一下样例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| ooooooo*******--
oooooo--******o* oooooo******--o*
ooooo--*****o*o* ooooo*****--o*o*
oooo--****o*o*o* oooo****--o*o*o*
ooo--***o*o*o*o*
ooo*o**--*o*o*o* o--*o**oo*o*o*o* o*o*o*--o*o*o*o* --o*o*o*o*o*o*o*
|
每两行分一组的时候,可以很明显地看到规律.
- 中间的 “o*” 与 “–” 交换
- 最左边的 “**” 与 “–” 交换
然而后四行我并没有发现什么规律,于是无耻地打了一个表.
打表原理:
1 2 3 4 5 6 7 8 9 10
| ooo*o**--* o*o*o* o--*o**oo* o*o*o* o*o*o*--o* o*o*o* --o*o*o*o* o*o*o* 后6个字符为固定的"o*o*o*" 于是只要记录 ooo*o**--*, o--*o**oo*, o*o*o*--o*, --o*o*o*o*
|
代码如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| #include <cstdio> #include <iostream> using namespace std; int n; char ch[205]; void swap(char &a, char &b) { char t = a; a = b; b = t; } void output(){ for (int i = 0; i < 2 * n + 2; i++) putchar(ch[i]); putchar('\n'); } void movechess(int start, int end) { swap(ch[start], ch[end]); swap(ch[start + 1], ch[end + 1]); output(); } string out[4] = {"ooo*o**--*", "o--*o**oo*", "o*o*o*--o*", "--o*o*o*o*"};
int main() { scanf("%d", &n); for (int i = 0; i < n; i++) ch[i] = 'o'; for (int i = n; i < 2 * n; i++) ch[i] = '*'; ch[2 * n] = '-'; ch[2 * n + 1] = '-'; output(); int len = n; while (true) { movechess(len - 1, 2 * len); len--; if (len == 3) break; movechess(len, 2 * len); } string ss; for (int i = 0; i < n - 4; i++) ss += "o*"; for (int i = 0; i < 4; i++) cout << out[i] << ss << endl; }
|