-
Notifications
You must be signed in to change notification settings - Fork 0
/
sudoku_advanced.c
45 lines (42 loc) · 930 Bytes
/
sudoku_advanced.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
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <inttypes.h>
#include "algx.c"
void run_sudoku() {
sz_t n;
scan:
scanf(" %lu", &n);
val_t vals[n*n*n*n];
for(sz_t i = 0; i < n*n*n*n; ++i) {
int sc = scanf(" %"SCNu8, &vals[i]);
assert(sc == 1);
assert(vals[i] <= n*n);
}
solve:;
sd_t *s = make_sd(n, vals);
RESULT res = solve_sd(s);
if(res != COMPLETE)goto show_res;
print:;
for(sz_t y = 0; y < s->ne2; ++y) {
for(sz_t x = 0; x < s->ne2; ++x) {
int t = s->table[y * s->ne2 + x];
int len = t ? 0 : 1;
while(t){t/=10;++len;}
for(int i=0;i<3-len;++i)putchar(' ');
printf("%"SCNu8, s->table[y * s->ne2 + x]);
}
putchar('\n');
}
show_res:
switch(res) {
case MULTIPLE: puts("MULTIPLE"); break;
case INVALID: puts("UNSOLVABLE"); break;
case COMPLETE:break;
}
free_sd(s);
}
int main() {
run_sudoku();
}