部分简单程序——叠框
1.叠框问题
解决思路:
- 四个角补充
- 从内向外逐圈向外构造
- 每圈都是正方形,用左上角和右下角的坐标表示一圈
- 将四个角扣掉
#include<iostream>
#include<cstdio>
using namespace std;
void A(char a[80][80], int lt,int rd,char c) {
for (int i = lt; i <= rd; i++) {
a[lt][i] = c;
a[rd][i] = c;
a[i][lt] = c;
a[i][rd] = c;
}
}
int main() {
int n; char b, c;
while (cin >> n >> b >> c) {
char b_c[2]; b_c[0] = b; b_c[1] = c;
char p[80][80]; int t=0;
for (int i = n/2; i>=0; i--) {
int lt = i, rd = n - i - 1;
A(p, lt, rd, b_c[(t++)%2]);
}
p[0][0] = ' ';
p[0][n-1] = ' ';
p[n-1][0] = ' ';
p[n-1][n-1] = ' ';
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cout << p[i][j];
}
cout << endl;
}
}
}