Problem Description
需要的时候,就把一个个大小差一圈的筐叠上去,使得从上往下看时,边筐花色交错。这个工作现在要让计算机来完成,得看你的了。
Input
输入是一个个的三元组,分别是,外筐尺寸n(n为满足0<n<80的奇整数),中心花色字符,外筐花色字符,后二者都为ASCII可见字符;
Output
输出叠在一起的筐图案,中心花色与外筐花色字符从内层起交错相叠,多筐相叠时,最外筐的角总是被打磨掉。叠筐与叠筐之间应有一行间隔。
Sample Input
11 B A
5 @ W
Sample Output
AAAAAAAAA
ABBBBBBBBBA
ABAAAAAAABA
ABABBBBBABA
ABABAAABABA
ABABABABABA
ABABAAABABA
ABABBBBBABA
ABAAAAAAABA
ABBBBBBBBBA
AAAAAAAAA
@@@
@WWW@
@W@W@
@WWW@
@@@
#include <iostream>
#include <vector>void op(int n, char ch1, char ch2);int main(int argc, const char *argv[])
{int n;char ch1, ch2;while(std::cin >> n >> ch1 >> ch2){static int i = 0;if(i != 0){ std::cout << std::endl;}if(1 == n){std::cout << ch1 << std::endl;}else{if((n / 2 + 1) % 2 == 0){op(n, ch2, ch1);}else{op(n, ch1, ch2);}}++ i;}return 0;
}void op(int n, char ch1, char ch2)
{std::vector<std::vector<char> > vec;for(int i = 0;i < n;++ i){std::vector<char> vecTemp;for(int j = 0;j < n;++ j){vecTemp.push_back(ch1);}vec.push_back(vecTemp);}for(int i = 0;i < n /2;++ i){for(int j = 2 * i + 1;j < n - 2 * i - 1;++ j){vec[2 * i + 1][j] = ch2;vec[n - 2 * i - 2][j] = ch2;vec[j][2 * i + 1] = ch2;vec[j][n - 2 * i - 2] = ch2;}}for(int i = 0;i < n;++ i){for(int j = 0;j < n;++ j){if(j == 0 && (i == 0 || i == n - 1)){std::cout << " ";}else if(j == n - 1 && (i == 0 || i == n - 1)){std::cout << " ";}else{std::cout << vec[i][j];}}std::cout << std::endl;}
}