diff --git a/loesung.c b/loesung.c index 32d402e6f300978abeb002b4ac28b095d73f90bb..822580b52327b5a624a2f7fbf3b1b0c19a33d847 100644 --- a/loesung.c +++ b/loesung.c @@ -85,7 +85,7 @@ void list_push(List *this, Tile *p_tile) { this->min.x = min(this->min.x, p_tile->x); this->min.y = min(this->min.y, p_tile->y); this->max.x = max(this->max.x, p_tile->x); - this->max.y = max(this->max.x, p_tile->y); + this->max.y = max(this->max.y, p_tile->y); this->num_tiles++; this->num_odd += (p_tile->x - p_tile->y)&1; } @@ -106,7 +106,7 @@ void list_free(List *this) { /** pruefen, ob genausoviele gerade und ungerade Kacheln existieren, * ohne einen Overflow zu erzeugen - * notwendiges Kriterium fuer + * notwendiges Kriterium */ bool list_necessity(List *this) { return this->num_tiles - this->num_odd == this->num_odd; @@ -115,8 +115,33 @@ bool list_necessity(List *this) { /** Zurueckgeben, ob graph ein vollstaendiges Rechteck ist */ bool list_rectangle(List *this) { // verwenden von `uint64_t` um einen ueberlauf zu vermeiden - return (uint64_t)(this->max.x - this->min.x) * (uint64_t)(this->max.y - this->min.y) - == (uint64_t)this->num_tiles; + return (uint64_t)(this->max.x - this->min.x+1) * (uint64_t)(this->max.y - this->min.y+1) + == (uint64_t)this->num_tiles; +} + +/** Ausgeben der Liste als Rechteck + * + * Voraussetzung: notwendiges Kriterium erfuellt & es handelt sich um ein Rechteck + */ +void list_print_rectangle(List *this) { + for (uint32_t y = this->min.y;; y++) { + for (uint32_t x = this->min.x;; x+=2) { + if (x == this->max.x - 1) { + if ((y - this->min.y) % 2 == 0) { + // vertikaler Stein + printf("%u %u;%u %u\n", x, y, x, y+1); + } + break; + } + printf("%u %u;%u %u\n", x, y, x+1, y); + if (x == this->max.x) { + break; + } + } + if(y == this->max.y) { + break; + } + } } typedef enum ReadResult { @@ -355,8 +380,7 @@ int main (void) return EXIT_SUCCESS; } if (list_rectangle(&tile_list)) { - printf("Rechteck"); - // TODO: Rechteck ausgabefunktion + list_print_rectangle(&tile_list); return EXIT_SUCCESS; }