[Blue Bridge Cup 2015 Preliminary Competition] Print Big X

Title description

Xiao Ming hopes to use asterisks to piece together and print a big X. He requires the ability to control the width of the strokes and the height of the entire character.
In order to facilitate the comparison of spaces, all white spaces are replaced with periods.
It is required to enter two integers mn, representing the width of the pen and the height of X.
Input
There are multiple sets of data.
Each set of test data input one line, including two integers, separated by spaces
(0<m<n, 3<n<1000, ensure that n is an odd number)
Output
requires a big X

Sample input

3 9
4 21

Sample output

***.....***
.***...***.
..***.***..
...*****...
....***....
...*****...
..***.***..
.***...***.
***.....***
****................****
.****..............****.
..****............****..
...****..........****...
....****........****....
.....****......****.....
......****....****......
.......****..****.......
........********........
.........******.........
..........****..........
.........******.........
........********........
.......****..****.......
......****....****......
.....****......****.....
....****........****....
...****..........****...
..****............****..
.****..............****.
****................****

code show as below:

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;

char a[1000][1000];

int main()
{
    
    
	int w, h;
	while(cin >> w >> h){
    
    
		int s = h-1+w;
		memset(a, 0 ,sizeof(a));
		for(int i = 0; i < h; i ++){
    
    
			for(int j = 0; j < s; j ++){
    
    
				if(j < w)
					a[i][j+i] = '*';
				if(j > (s-w)-1)
					a[i][j-i] = '*';
			}	
		}
		for(int i = 0; i < h; i ++){
    
    
			for(int j = 0; j < s; j ++)
				if(a[i][j] != '*')cout << ".";
				else cout << a[i][j];
			cout << endl;	
		}
	}
	
	return 0;
}

Guess you like

Origin blog.csdn.net/diviner_s/article/details/108918085
Recommended