-
Notifications
You must be signed in to change notification settings - Fork 0
/
poj3752.c
77 lines (64 loc) · 1.51 KB
/
poj3752.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* Problem: 3752, Character Rotation
* User: LoiteringLeo
* Memory: 400K Time: 16MS
* Language: GCC Result: Accepted
*/
#include <stdio.h>
#include <string.h>
#define MAX_N 1024
char matrix[MAX_N + 1][ MAX_N + 1];
void draw_circle(char start, int low, int high, int left, int right)
{
int i;
#if 0
printf("left = %d, right = %d, low = %d, high = %d, start = %c\n",
left, right, low, high, start);
#endif
if (left > right || low > high) {
#if 0
printf("stop\n");
#endif
return;
}
for (i = left; i <= right; i++) {
matrix[low][i] = (start - 'A') % 26 + 'A';
start++;
}
for (i = low + 1; i <= high; i++) {
matrix[i][right] = (start - 'A') % 26 + 'A';
start++;
}
if (high > low) {
for (i = right - 1; i >= left; i--) {
matrix[high][i] = (start - 'A') % 26 + 'A';
start++;
}
}
if (right > left) {
for (i = high - 1; i > low; i--) {
matrix[i][left] = (start - 'A') % 26 + 'A';
start++;
}
}
if (left + 1 <= right - 1 && low + 1 <= right - 1 ) {
draw_circle((start - 'A') % 26 + 'A', low + 1, high - 1, left + 1, right - 1);
}
return;
}
int main()
{
int m;
int n;
int i;
int j;
scanf("%d %d", &m, &n);
draw_circle('A', 1, m, 1, n);
for (i = 1; i <= m; i++) {
for (j = 1; j <= n; j++) {
printf(" %c", matrix[i][j]);
}
printf("\n");
}
return 0;
}