Stacking baskets - C language implementation

Description of the problem:
When we need to use baskets, we stack baskets with different sizes so that when looking from top to bottom, the colors of the side baskets are staggered. Now it's up to you to let the computer do the job.
Input description:
The input is a triplet, namely, outer basket size n (n is an odd integer satisfying 1 ≤ n ≤ 79), center color character, outer basket color character, the latter two are ASCII visible characters ,There are multiple sets of input data.
Output description:
Output the stacked basket pattern. The characters of the center design and the outer basket design are staggered and overlapped from the inner layer. When multiple baskets are stacked, the corners of the outermost basket are always polished off. There should be a line of space between stacked baskets.
Example 1
input

11 * +
5 W @

output

 +++++++++ 
+*********+
+*+++++++*+
+*+*****+*+
+*+*+++*+*+
+*+*+*+*+*+
+*+*+++*+*+
+*+*****+*+
+*+++++++*+
+*********+
 +++++++++ 

 WWW 
W@@@W
W@W@W
W@@@W
 WWW 
#include<stdio.h>
#include<stdbool.h>
int main(void) {
    
    
	char a, b, c;
	int start, end, length, k;
	int n;
	char matrix[80][80];
	bool firstFlag = true;
	while (scanf("%d %c %c", &n, &a, &b) != EOF) {
    
    
		if (firstFlag) {
    
    
			firstFlag = false;
		}
		else {
    
    
			printf("\n");
		}
		for (start = 0; start <= n / 2; start++) {
    
    
			end = n - 1 - start;
			length = end - start + 1;
			if ((n/2-start+1) % 2 == 0) {
    
    
				c = b;
			}
			else {
    
    
				c = a;
			}
			for (k = 0; k < length; k++) {
    
    
				matrix[start][start + k] = c;
				matrix[end][end - k] = c;
				matrix[start + k][start] = c;
				matrix[end - k][end] = c;
			}
		}
        if(n!=1){
    
    
            matrix[0][0] = ' ';
            matrix[0][n - 1] = ' ';
            matrix[n - 1][0] = ' ';
            matrix[n - 1][n - 1] = ' ';
        }
		for (start = 0; start < n; start++) {
    
    
			for (end = 0; end < n; end++) {
    
    
				printf("%c", matrix[start][end]);
			}
			printf("\n");
		}
	}
	return 0;
}

Guess you like

Origin blog.csdn.net/weixin_43489041/article/details/106543941