【学习笔记】〖九度OJ〗题目1432:叠筐
排版题,可以利用先排版再输出的方法
#include<iostream> using namespace std; char map[82][82]; void draw(char c[82][82], char item, int s, int e) { for (int i=s; i<e; i++) { for (int j=s; j<e; j++) { c[i][j] = item; } } } int main() { bool first = true; int n, i, j; char a,b; char items[2]; while (cin >> n) { if (first) { first = false; } else { cout << endl; } cin >> a >> b; if (((n-1)/2)%2)//判断外层需要用哪个字符填充 { items[1] = a; items[0] = b; } else { items[0] = a; items[1] = b; } for (i=0; i<n; i++) { draw(map, items[i%2], i, n-i); } if (n>1) { map[0][0] = ' '; map[0][n-1] = ' '; map[n-1][0] = ' '; map[n-1][n-1] = ' '; } for (i=0; i<n; i++) { for (j=0; j<n; j++) { cout << map[i][j]; } cout << endl; } } return 0; }