50170. Draw a Rectangle

難度:4.9/5 Used Time: 40:53 Used Time: 15:36

邏輯好難

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <stdio.h>
#include <string.h>
#include "fill_rectangle.h"

void fill_rectangle_neg(int *upper_left, int *bottom_right, int n_row, int n_col, int fill){
int m = (bottom_right - upper_left) % n_col + 1;
int n = (bottom_right - upper_left) / n_col + 1;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
*(upper_left + (i * n_col + j)) = fill;
}
}
}
void fill_rectangle_pos(int *upper_right, int *bottom_left, int n_row, int n_col, int fill){
int r = (n_col + bottom_left - upper_right) % n_col;
int m = (n_col - r) % n_col + 1;
fill_rectangle_neg(upper_right - (m - 1), bottom_left + (m - 1),
n_row, n_col, fill);
}


50170. Draw a Rectangle
https://aaronlin1229.github.io/judgegirl_50170/
Author
Akizumi
Posted on
July 17, 2023
Licensed under