题目描述
小明希望用星号拼凑,打印出一个大X,他要求能够控制笔画的宽度和整个字的高度。
为了便于比对空格,所有的空白位置都以句点符来代替。
输入
要求输入两个整数m n,表示笔的宽度,X的高度。用空格分开(0<m<n, 3<n<1000, 保证n是奇数)
输出
输出对应的图形
样例输入
3 9
样例输出
***.....***
.***...***.
..***.***..
...*****...
....***....
...*****...
..***.***..
.***...***.
***.....***
解决方案
代码
#include <iostream>
#include <string.h>
using namespace std;
int main() {
char arr[1000][2000];
memset(arr, '.', sizeof(arr));
int n, m;
scanf("%d", &n);
scanf("%d", &m);
int h = m;
int w = (h + (n - 2) * 2);
int x, y;
x = (w - 1) / 2 - n / 2;
y = (h - 1) / 2;
while ((x != -1) && (y != -1)) {
for (int i = 0; i < n; ++i) {
//右上角
arr[y][x + i] = '*';
//左上角
arr[y][(w - 1) - (x + i)] = '*';
//右下角
arr[(h - 1) - y][x + i] = '*';
//左下角
arr[(h - 1) - y][(w - 1) - (x + i)] = '*';
}
x--;
y--;
}
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
cout << arr[i][j];
}
cout << endl;
}
return 0;
}