Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
38
Task/Cantor-set/C/cantor-set-1.c
Normal file
38
Task/Cantor-set/C/cantor-set-1.c
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#define WIDTH 81
|
||||
#define HEIGHT 5
|
||||
|
||||
char lines[HEIGHT][WIDTH];
|
||||
|
||||
void init() {
|
||||
int i, j;
|
||||
for (i = 0; i < HEIGHT; ++i) {
|
||||
for (j = 0; j < WIDTH; ++j) lines[i][j] = '*';
|
||||
}
|
||||
}
|
||||
|
||||
void cantor(int start, int len, int index) {
|
||||
int i, j, seg = len / 3;
|
||||
if (seg == 0) return;
|
||||
for (i = index; i < HEIGHT; ++i) {
|
||||
for (j = start + seg; j < start + seg * 2; ++j) lines[i][j] = ' ';
|
||||
}
|
||||
cantor(start, seg, index + 1);
|
||||
cantor(start + seg * 2, seg, index + 1);
|
||||
}
|
||||
|
||||
void print() {
|
||||
int i, j;
|
||||
for (i = 0; i < HEIGHT; ++i) {
|
||||
for (j = 0; j < WIDTH; ++j) printf("%c", lines[i][j]);
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
init();
|
||||
cantor(0, WIDTH, 1);
|
||||
print();
|
||||
return 0;
|
||||
}
|
||||
28
Task/Cantor-set/C/cantor-set-2.c
Normal file
28
Task/Cantor-set/C/cantor-set-2.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#define WIDTH 81
|
||||
|
||||
int l, w, n, i;
|
||||
|
||||
void split (char* s)
|
||||
{
|
||||
l /= 3; n = 0;
|
||||
|
||||
do {
|
||||
n += l; if (s[n] != ' ') for (i = 0; i < l; i++) s[n+i] = ' '; n += l+l;
|
||||
} while (n < w);
|
||||
}
|
||||
|
||||
void go (char* s)
|
||||
{
|
||||
puts (s); do { split (s); puts (s); } while (l > 1);
|
||||
}
|
||||
|
||||
int main ()
|
||||
{
|
||||
char s[WIDTH+1];
|
||||
|
||||
l = w = WIDTH;
|
||||
for (i = 0; i < WIDTH; i++) s[i] = '#'; s[WIDTH] = '\0'; go (s);
|
||||
return (0);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue