This commit is contained in:
2021-10-09 20:23:02 +02:00
parent 4031ad1831
commit bd4e76b246
11 changed files with 980 additions and 9 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
CMakeFiles
.cache
a[1-5]

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "a2-Vollgeladen/lib/advanced_C_standard_library"]
path = a2-Vollgeladen/lib/advanced_C_standard_library
url = https://git.zinkel.org/MrGeorgen/advanced_C_standard_library.git

View File

@ -0,0 +1,124 @@
# Schiebeparkplatz
## Lösungsidee
Für jede normale Textdatei wird ASCII encoding verwendet bzw. ein Encoding
Standart welcher auf ASCII basiert und zusätzliche Sonderzeichen enthält,
wobei die Werte die bereits in ASCII enthalten übernommen wurden.
Die ASCII codes für die Buchstaben sind entsprechend des Alphabets
hintereinander angeordnet. Dies ist sehr nützlich, da somit eine Liste der
Buchstaben und deren Position im Alphabet nicht benötigt wird.<br>
Zur Lösung des Parkplatzproblems werden die Autos wenn möglich nach links bzw.
rechts verschoben bis die Parklücke frei ist. Je nachdem in welche Richtung
weniger Autos verschoben werden müssen, wird die Verschiebungsrichtung gewählt.
## Umsetzung
Da die Lösung des Problem keine besondere Library benötigt wird und die Anforderungen
an die Ausführungsgeschwindigkeit gering sind, hätte man fast jede Progmiersprache
wählen können. Ich habe mich für Go entschieden.<br>
Das Programm akzeptiert als Argumente eine beliebige Anzahl an Pfaden zu Parkplatzdatein.
Für das Iterieren über die Argumente wird eine for-Schleife benutzt.
Innerhalb der Schleife wird die Eingabedatei ausgelesen. Anhand des ersten und letzten
Buchstaben der Autos auf den normalen Parkplätzen wird die die Anzahl an Parkplätzen
bestimmt. Anschließend wird eine Slice (ein dynamisch vergrößerbares Array in Go)
mit den Buchstaben der quer parkenden Autos befüllt an den Indexen an denen sie die
normalen Parkplätze blockieren.<br>
In einer for-Schleife wird die "move"-Funktion je Index der Parkplätze doppelt
für beide Verschiebungsrichtungen aufgerufen.
In der "move"-Funktion wird ein Auto verschoben, wenn nicht das Ende des
Parkplatzes erreicht ist. Die Funktion ruft sich recursive auf um weitere Autos zu
verschieben. Je nachdem in welche Richtung weniger Autos verschoben werden müssen
oder, wenn es gleich viele sind, wo die Anzahl der verschobenen Plätze aller Autos
geringer ist, wird sich für das Verschieben in diese Richtung entschieden.
## Beispiele
```
parkplatz0.txt:
A:
B:
C: H 1 rechts
D: H 1 links
E:
F: H 1 links, I 2 links
G: I 1 links
parkplatz1.txt:
A:
B: O 1 rechts, P 1 rechts
C: O 1 links
D: P 1 rechts
E: O 1 links, P 1 links
F:
G: Q 1 rechts
H: Q 1 links
I:
J:
K: R 1 rechts
L: R 1 links
M:
N:
parkplatz2.txt:
A:
B:
C: O 1 rechts
D: O 1 links
E:
F: O 1 links, P 2 links
G: P 1 links
H: Q 1 rechts, R 1 rechts
I: P 1 links, Q 1 links
J: R 1 rechts
K: P 1 links, Q 1 links, R 1 links
L:
M: P 1 links, Q 1 links, R 1 links, S 2 links
N: S 1 links
parkplatz3.txt:
A:
B: O 1 rechts
C: O 1 links
D:
E: P 1 rechts
F: P 1 links
G:
H:
I: Q 2 links
J: Q 1 links
K: Q 2 links, R 2 links
L: Q 1 links, R 1 links
M: Q 2 links, R 2 links, S 2 links
N: Q 1 links, R 1 links, S 1 links
parkplatz4.txt:
A: Q 1 rechts, R 1 rechts
B: Q 2 rechts, R 2 rechts
C: R 1 rechts
D: R 2 rechts
E:
F:
G: S 1 rechts
H: S 1 links
I:
J:
K: T 1 rechts
L: T 1 links
M:
N: U 1 rechts
O: U 1 links
P:
parkplatz5.txt:
A:
B:
C: P 2 links
D: P 1 links
E: Q 1 rechts
F: Q 2 rechts
G:
H:
I: R 1 rechts
J: R 1 links
K:
L:
M: S 1 rechts
N: S 1 links
O:
```

View File

@ -5,7 +5,6 @@ import (
"io/ioutil"
"strings"
"strconv"
"math"
"fmt"
"sort"
)
@ -18,39 +17,62 @@ type movedCar struct {
var querAutos []byte
func main() {
// Dem Programm können beliebig viele Eingabedatein übergeben werden.
for _, filepath := range os.Args[1:] {
fmt.Printf("%s: \n", filepath)
rawFile, err := ioutil.ReadFile(filepath)
// ausgeben des Dateipfades, um Zuordnung der Lösung zu der entsprechenden Eingabedatei zu ermöglichen
fmt.Printf("%s:\n", filepath)
rawFile, err := ioutil.ReadFile(filepath) // lesen der Eingabedatei
throw(err)
input := string(rawFile)
firstChar := input[0]
firstChar := input[0] // firstChar ist der Buchstabe mit dem das erste Auto gekennzeichnet wird.
/* querAutos ist ein Array bzw. slice, wie dynamisch vergrößerbare Arrays in Go benannt werden,
welches die Autos, die quer auf dem Parkplatz parken, enthält. input[2] ist der Buchstabe vom letztem Auto.
Die Größe der slice bzw. die Anzahl der senkrecht parkenden Autos wird durch die Differenz der ASCII Codes
berechnet. */
querAutos = make([]byte, input[2] - firstChar + 1)
// teilt den Text in Zeilen auf und iteriert über die Zeilen ab Zeile 3
for _, line := range strings.Split(input, "\n")[2:] {
// auf Unix Systemen enden die Textdatei auf einem newline Zeichen. Deshalb hat unsere letzte "Zeile" die Länge 0 und wird übersprungen.
if len(line) == 0 {
continue
}
// Die Position des des quer stehenden Autos beginnt ab dem 3. Zeichen (Index 2) bis zum Ende der Zeile.
i, err := strconv.Atoi(line[2:])
throw(err)
// Jedes quer stehende Auto blockiert zwei Parkplätze. Deshalb belegt es auch zwei Plätze in unserer Slice.
querAutos[i], querAutos[i + 1] = line[0], line[0]
}
for i := range querAutos {
var currentMoves []movedCar
var carLeastSteps uint32 = math.MaxUint32
for _, direction := range []int{-1, 1} {
var currentMoves []movedCar // enthält die Verschiebungen der Autos in die Richtung in der weniger Autos verschoben werden müssen
var carLeastSteps uint32
for _, direction := range []int{-1, 1} { // -1 steht für links und 1 für rechts
movedCars, steps, success := move(i, direction, []movedCar{}, 0, 0)
/* Wenn das Verschieben der Autos in der jeweiligen Richtung erfolgreich ist und noch keine
Verschiebungen abgespeichert wurden, d. h. gerade die Verschiebungen für links berechnet
wurden oder das Verschieben nach links nicht erfolgreich war, da das Ende das Parkplatzes
erreicht wurde, dann werden die Verschiebungen abgespeichert.
Sollten allerdings bereits Verschiebungen für links vorhanden sein, wird das Verschieben nach
rechts bevorzugt, wenn weniger Autos verschoben werden mussten oder die Autos weniger Plätze
verschoben werden mussten. */
if success && (currentMoves == nil || len(movedCars) < len(currentMoves) || len(movedCars) == len(currentMoves) && steps < carLeastSteps) {
currentMoves = movedCars
carLeastSteps = steps
}
}
// sortiert die verschoben Autos alphabetisch
sort.Slice(currentMoves, func(i, j int) bool {
return currentMoves[i].id < currentMoves[j].id
})
fmt.Printf("%s: ", string(firstChar + byte(i)))
fmt.Printf("%s: ", string(firstChar + byte(i))) // gibt den Buchstaben für das jeweilige Auto auf den normalen Parkplatz aus.
for j, car := range currentMoves {
if(j != 0) {
fmt.Print(", ")
}
// gibt aus welches Auto wie viele Plätze in welche Richtung verschoben wurde.
fmt.Printf("%s %d ", string(car.id), car.steps)
if car.direction == 1 {
fmt.Print("rechts")
@ -63,34 +85,52 @@ func main() {
}
}
// Funktion um im Falle eines Fehlers, den Fehler auszugeben und das Programm zu beenden.
func throw(err error) {
if err != nil {
panic(err)
}
}
// Funktion zur Berechung der Autos, die für einen Parkplatz verschoben werden müssen.
func move(i, direction int, movedCars []movedCar, lastMoved byte, totalSteps uint32) ([]movedCar, uint32, bool) {
querAuto := querAutos[i]
/* Wenn querAuto gleich 0 ist, ist kein Auto vor dem Parkplatz.
Wenn es das gleiche Auto ist wie das zuletzt verschobene, ist auch das Verschieben beendet,
da dieses Auto bereits ausreichend verschoben wurde. */
if querAuto == 0 || querAuto == lastMoved {
return movedCars, totalSteps, true
}
/* Wenn neben unserem Auto in der jeweiligen Richtung kein Parkplatz mehr ist,
dann können auch keine Autos in diese Richtung verschoben werden. */
if outOfBounds(querAutos, i + direction) {
return movedCars, totalSteps, false
}
var steps int
/* Wenn sich eins nach der Verschiebungsrichtung auch unserer quer parkendes Auto befindet,
muss es nur um einen Platz verschoben werden, ansonsten um zwei. */
if querAutos[i + direction] == querAuto {
steps = 1
} else {
steps = 2
}
endCar := i + direction * 2
endCar := i + direction * 2 // ist das Ende des verschobenen Autos, das realtiv zur verschobenen Richtung, vorne ist.
/* müsste das Auto ausserhalb des Parkplatzes geschoben werden,
damit unser normale Parkplatz frei wird, ist das Verschieben in diese Richtung nicht möglich. */
if outOfBounds(querAutos, endCar) {
return movedCars, totalSteps, false
}
// fügt das gerade verschobene Auto der Slice mit den verschobenen Autos hinzu.
movedCars = append(movedCars, movedCar{querAuto, steps, direction})
/* ruft die Funktion recursive auf, mit dem Index des Parkplatzes an dem
noch ein quer stehendes Auto stehen könnte, das verschoben werden müsste. */
return move(endCar, direction, movedCars, querAuto, totalSteps + uint32(steps))
}
// Funktion um zu überprüfen, ob ein Index innerhalb einer Slice liegt.
func outOfBounds(slice []byte, i int) bool {
return i < 0 || i >= len(slice)
}

View File

@ -0,0 +1,371 @@
# This is the CMakeCache file.
# For build in directory: /home/mrgeorgen/dev/bwinf40-runde1/a2-Vollgeladen
# It was generated by CMake: /usr/bin/cmake
# You can edit this file to change values found and used by cmake.
# If you do not want to change any of the values, simply exit the editor.
# If you do want to change a value, simply edit, save, and exit the editor.
# The syntax for the file is as follows:
# KEY:TYPE=VALUE
# KEY is the name of a variable in the cache.
# TYPE is a hint to GUIs for the type of VALUE, DO NOT EDIT TYPE!.
# VALUE is the current value for the KEY.
########################
# EXTERNAL cache entries
########################
//Path to a program.
CMAKE_ADDR2LINE:FILEPATH=/usr/bin/addr2line
//Path to a program.
CMAKE_AR:FILEPATH=/usr/bin/ar
//Choose the type of build, options are: None Debug Release RelWithDebInfo
// MinSizeRel ...
CMAKE_BUILD_TYPE:STRING=Debug
//Enable/Disable color output during build.
CMAKE_COLOR_MAKEFILE:BOOL=ON
//CXX compiler
CMAKE_CXX_COMPILER:STRING=/usr/bin/c++
//A wrapper around 'ar' adding the appropriate '--plugin' option
// for the GCC compiler
CMAKE_CXX_COMPILER_AR:FILEPATH=/usr/bin/gcc-ar
//A wrapper around 'ranlib' adding the appropriate '--plugin' option
// for the GCC compiler
CMAKE_CXX_COMPILER_RANLIB:FILEPATH=/usr/bin/gcc-ranlib
//Flags used by the CXX compiler during all build types.
CMAKE_CXX_FLAGS:STRING=
//Flags used by the CXX compiler during DEBUG builds.
CMAKE_CXX_FLAGS_DEBUG:STRING=-g
//Flags used by the CXX compiler during MINSIZEREL builds.
CMAKE_CXX_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG
//Flags used by the CXX compiler during RELEASE builds.
CMAKE_CXX_FLAGS_RELEASE:STRING=-O3 -DNDEBUG
//Flags used by the CXX compiler during RELWITHDEBINFO builds.
CMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG
//C compiler
CMAKE_C_COMPILER:STRING=/usr/bin/cc
//A wrapper around 'ar' adding the appropriate '--plugin' option
// for the GCC compiler
CMAKE_C_COMPILER_AR:FILEPATH=/usr/bin/gcc-ar
//A wrapper around 'ranlib' adding the appropriate '--plugin' option
// for the GCC compiler
CMAKE_C_COMPILER_RANLIB:FILEPATH=/usr/bin/gcc-ranlib
//Flags used by the C compiler during all build types.
CMAKE_C_FLAGS:STRING=
//Flags used by the C compiler during DEBUG builds.
CMAKE_C_FLAGS_DEBUG:STRING=-g
//Flags used by the C compiler during MINSIZEREL builds.
CMAKE_C_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG
//Flags used by the C compiler during RELEASE builds.
CMAKE_C_FLAGS_RELEASE:STRING=-O3 -DNDEBUG
//Flags used by the C compiler during RELWITHDEBINFO builds.
CMAKE_C_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG
//Path to a program.
CMAKE_DLLTOOL:FILEPATH=CMAKE_DLLTOOL-NOTFOUND
//Flags used by the linker during all build types.
CMAKE_EXE_LINKER_FLAGS:STRING=
//Flags used by the linker during DEBUG builds.
CMAKE_EXE_LINKER_FLAGS_DEBUG:STRING=
//Flags used by the linker during MINSIZEREL builds.
CMAKE_EXE_LINKER_FLAGS_MINSIZEREL:STRING=
//Flags used by the linker during RELEASE builds.
CMAKE_EXE_LINKER_FLAGS_RELEASE:STRING=
//Flags used by the linker during RELWITHDEBINFO builds.
CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO:STRING=
//Enable/Disable output of compile commands during generation.
CMAKE_EXPORT_COMPILE_COMMANDS:BOOL=
//Install path prefix, prepended onto install directories.
CMAKE_INSTALL_PREFIX:PATH=/usr/local
//Path to a program.
CMAKE_LINKER:FILEPATH=/usr/bin/ld
//Path to a program.
CMAKE_MAKE_PROGRAM:FILEPATH=/usr/bin/make
//Flags used by the linker during the creation of modules during
// all build types.
CMAKE_MODULE_LINKER_FLAGS:STRING=
//Flags used by the linker during the creation of modules during
// DEBUG builds.
CMAKE_MODULE_LINKER_FLAGS_DEBUG:STRING=
//Flags used by the linker during the creation of modules during
// MINSIZEREL builds.
CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL:STRING=
//Flags used by the linker during the creation of modules during
// RELEASE builds.
CMAKE_MODULE_LINKER_FLAGS_RELEASE:STRING=
//Flags used by the linker during the creation of modules during
// RELWITHDEBINFO builds.
CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO:STRING=
//Path to a program.
CMAKE_NM:FILEPATH=/usr/bin/nm
//Path to a program.
CMAKE_OBJCOPY:FILEPATH=/usr/bin/objcopy
//Path to a program.
CMAKE_OBJDUMP:FILEPATH=/usr/bin/objdump
//Value Computed by CMake
CMAKE_PROJECT_DESCRIPTION:STATIC=
//Value Computed by CMake
CMAKE_PROJECT_HOMEPAGE_URL:STATIC=
//Value Computed by CMake
CMAKE_PROJECT_NAME:STATIC=a2-Vollgeladen
//Path to a program.
CMAKE_RANLIB:FILEPATH=/usr/bin/ranlib
//Path to a program.
CMAKE_READELF:FILEPATH=/usr/bin/readelf
//Flags used by the linker during the creation of shared libraries
// during all build types.
CMAKE_SHARED_LINKER_FLAGS:STRING=
//Flags used by the linker during the creation of shared libraries
// during DEBUG builds.
CMAKE_SHARED_LINKER_FLAGS_DEBUG:STRING=
//Flags used by the linker during the creation of shared libraries
// during MINSIZEREL builds.
CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL:STRING=
//Flags used by the linker during the creation of shared libraries
// during RELEASE builds.
CMAKE_SHARED_LINKER_FLAGS_RELEASE:STRING=
//Flags used by the linker during the creation of shared libraries
// during RELWITHDEBINFO builds.
CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO:STRING=
//If set, runtime paths are not added when installing shared libraries,
// but are added when building.
CMAKE_SKIP_INSTALL_RPATH:BOOL=NO
//If set, runtime paths are not added when using shared libraries.
CMAKE_SKIP_RPATH:BOOL=NO
//Flags used by the linker during the creation of static libraries
// during all build types.
CMAKE_STATIC_LINKER_FLAGS:STRING=
//Flags used by the linker during the creation of static libraries
// during DEBUG builds.
CMAKE_STATIC_LINKER_FLAGS_DEBUG:STRING=
//Flags used by the linker during the creation of static libraries
// during MINSIZEREL builds.
CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL:STRING=
//Flags used by the linker during the creation of static libraries
// during RELEASE builds.
CMAKE_STATIC_LINKER_FLAGS_RELEASE:STRING=
//Flags used by the linker during the creation of static libraries
// during RELWITHDEBINFO builds.
CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO:STRING=
//Path to a program.
CMAKE_STRIP:FILEPATH=/usr/bin/strip
//If this value is on, makefiles will be generated without the
// .SILENT directive, and all commands will be echoed to the console
// during the make. This is useful for debugging only. With Visual
// Studio IDE projects all commands are done without /nologo.
CMAKE_VERBOSE_MAKEFILE:BOOL=FALSE
//Value Computed by CMake
a2-Vollgeladen_BINARY_DIR:STATIC=/home/mrgeorgen/dev/bwinf40-runde1/a2-Vollgeladen
//Value Computed by CMake
a2-Vollgeladen_IS_TOP_LEVEL:STATIC=ON
//Value Computed by CMake
a2-Vollgeladen_SOURCE_DIR:STATIC=/home/mrgeorgen/dev/bwinf40-runde1/a2-Vollgeladen
########################
# INTERNAL cache entries
########################
//ADVANCED property for variable: CMAKE_ADDR2LINE
CMAKE_ADDR2LINE-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_AR
CMAKE_AR-ADVANCED:INTERNAL=1
//This is the directory where this CMakeCache.txt was created
CMAKE_CACHEFILE_DIR:INTERNAL=/home/mrgeorgen/dev/bwinf40-runde1/a2-Vollgeladen
//Major version of cmake used to create the current loaded cache
CMAKE_CACHE_MAJOR_VERSION:INTERNAL=3
//Minor version of cmake used to create the current loaded cache
CMAKE_CACHE_MINOR_VERSION:INTERNAL=21
//Patch version of cmake used to create the current loaded cache
CMAKE_CACHE_PATCH_VERSION:INTERNAL=3
//ADVANCED property for variable: CMAKE_COLOR_MAKEFILE
CMAKE_COLOR_MAKEFILE-ADVANCED:INTERNAL=1
//Path to CMake executable.
CMAKE_COMMAND:INTERNAL=/usr/bin/cmake
//Path to cpack program executable.
CMAKE_CPACK_COMMAND:INTERNAL=/usr/bin/cpack
//Path to ctest program executable.
CMAKE_CTEST_COMMAND:INTERNAL=/usr/bin/ctest
//ADVANCED property for variable: CMAKE_CXX_COMPILER
CMAKE_CXX_COMPILER-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_CXX_COMPILER_AR
CMAKE_CXX_COMPILER_AR-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_CXX_COMPILER_RANLIB
CMAKE_CXX_COMPILER_RANLIB-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_DEBUG-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_RELEASE-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_C_COMPILER
CMAKE_C_COMPILER-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_C_COMPILER_AR
CMAKE_C_COMPILER_AR-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_C_COMPILER_RANLIB
CMAKE_C_COMPILER_RANLIB-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_C_FLAGS
CMAKE_C_FLAGS-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_DEBUG-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_C_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_RELEASE-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_DLLTOOL
CMAKE_DLLTOOL-ADVANCED:INTERNAL=1
//Path to cache edit program executable.
CMAKE_EDIT_COMMAND:INTERNAL=/usr/bin/ccmake
//Executable file format
CMAKE_EXECUTABLE_FORMAT:INTERNAL=ELF
//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS
CMAKE_EXE_LINKER_FLAGS-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_DEBUG
CMAKE_EXE_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_MINSIZEREL
CMAKE_EXE_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_RELEASE
CMAKE_EXE_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO
CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_EXPORT_COMPILE_COMMANDS
CMAKE_EXPORT_COMPILE_COMMANDS-ADVANCED:INTERNAL=1
//Name of external makefile project generator.
CMAKE_EXTRA_GENERATOR:INTERNAL=
//Name of generator.
CMAKE_GENERATOR:INTERNAL=Unix Makefiles
//Generator instance identifier.
CMAKE_GENERATOR_INSTANCE:INTERNAL=
//Name of generator platform.
CMAKE_GENERATOR_PLATFORM:INTERNAL=
//Name of generator toolset.
CMAKE_GENERATOR_TOOLSET:INTERNAL=
//Source directory with the top level CMakeLists.txt file for this
// project
CMAKE_HOME_DIRECTORY:INTERNAL=/home/mrgeorgen/dev/bwinf40-runde1/a2-Vollgeladen
//Install .so files without execute permission.
CMAKE_INSTALL_SO_NO_EXE:INTERNAL=0
//ADVANCED property for variable: CMAKE_LINKER
CMAKE_LINKER-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_MAKE_PROGRAM
CMAKE_MAKE_PROGRAM-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS
CMAKE_MODULE_LINKER_FLAGS-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_DEBUG
CMAKE_MODULE_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL
CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_RELEASE
CMAKE_MODULE_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO
CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_NM
CMAKE_NM-ADVANCED:INTERNAL=1
//number of local generators
CMAKE_NUMBER_OF_MAKEFILES:INTERNAL=1
//ADVANCED property for variable: CMAKE_OBJCOPY
CMAKE_OBJCOPY-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_OBJDUMP
CMAKE_OBJDUMP-ADVANCED:INTERNAL=1
//Platform information initialized
CMAKE_PLATFORM_INFO_INITIALIZED:INTERNAL=1
//ADVANCED property for variable: CMAKE_RANLIB
CMAKE_RANLIB-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_READELF
CMAKE_READELF-ADVANCED:INTERNAL=1
//Path to CMake installation.
CMAKE_ROOT:INTERNAL=/usr/share/cmake-3.21
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS
CMAKE_SHARED_LINKER_FLAGS-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_DEBUG
CMAKE_SHARED_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL
CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_RELEASE
CMAKE_SHARED_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO
CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_SKIP_INSTALL_RPATH
CMAKE_SKIP_INSTALL_RPATH-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_SKIP_RPATH
CMAKE_SKIP_RPATH-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS
CMAKE_STATIC_LINKER_FLAGS-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_DEBUG
CMAKE_STATIC_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL
CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_RELEASE
CMAKE_STATIC_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO
CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_STRIP
CMAKE_STRIP-ADVANCED:INTERNAL=1
//uname command
CMAKE_UNAME:INTERNAL=/usr/bin/uname
//ADVANCED property for variable: CMAKE_VERBOSE_MAKEFILE
CMAKE_VERBOSE_MAKEFILE-ADVANCED:INTERNAL=1

View File

@ -0,0 +1,9 @@
project(a2-Vollgeladen)
cmake_minimum_required(VERSION 3.16)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
include_directories("lib/advanced_C_standard_library/include")
file(GLOB SOURCES "src/*.c")
file(GLOB ACLSOURCES "lib/advanced_C_standard_library/src/*.c")
add_executable(a2 ${SOURCES} ${ACLSOURCES})
target_link_libraries(a2 PRIVATE m)
set_property(TARGET a2 PROPERTY C_STANDARD 99)

262
a2-Vollgeladen/Makefile Normal file
View File

@ -0,0 +1,262 @@
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.21
# Default target executed when no arguments are given to make.
default_target: all
.PHONY : default_target
# Allow only one "make -f Makefile2" at a time, but pass parallelism.
.NOTPARALLEL:
#=============================================================================
# Special targets provided by cmake.
# Disable implicit rules so canonical targets will work.
.SUFFIXES:
# Disable VCS-based implicit rules.
% : %,v
# Disable VCS-based implicit rules.
% : RCS/%
# Disable VCS-based implicit rules.
% : RCS/%,v
# Disable VCS-based implicit rules.
% : SCCS/s.%
# Disable VCS-based implicit rules.
% : s.%
.SUFFIXES: .hpux_make_needs_suffix_list
# Command-line flag to silence nested $(MAKE).
$(VERBOSE)MAKESILENT = -s
#Suppress display of executed commands.
$(VERBOSE).SILENT:
# A target that is always out of date.
cmake_force:
.PHONY : cmake_force
#=============================================================================
# Set environment variables for the build.
# The shell in which to execute make rules.
SHELL = /bin/sh
# The CMake executable.
CMAKE_COMMAND = /usr/bin/cmake
# The command to remove a file.
RM = /usr/bin/cmake -E rm -f
# Escaping for special characters.
EQUALS = =
# The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = /home/mrgeorgen/dev/bwinf40-runde1/a2-Vollgeladen
# The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = /home/mrgeorgen/dev/bwinf40-runde1/a2-Vollgeladen
#=============================================================================
# Targets provided globally by CMake.
# Special rule for the target rebuild_cache
rebuild_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
/usr/bin/cmake --regenerate-during-build -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : rebuild_cache
# Special rule for the target rebuild_cache
rebuild_cache/fast: rebuild_cache
.PHONY : rebuild_cache/fast
# Special rule for the target edit_cache
edit_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..."
/usr/bin/ccmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : edit_cache
# Special rule for the target edit_cache
edit_cache/fast: edit_cache
.PHONY : edit_cache/fast
# The main all target
all: cmake_check_build_system
$(CMAKE_COMMAND) -E cmake_progress_start /home/mrgeorgen/dev/bwinf40-runde1/a2-Vollgeladen/CMakeFiles /home/mrgeorgen/dev/bwinf40-runde1/a2-Vollgeladen//CMakeFiles/progress.marks
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 all
$(CMAKE_COMMAND) -E cmake_progress_start /home/mrgeorgen/dev/bwinf40-runde1/a2-Vollgeladen/CMakeFiles 0
.PHONY : all
# The main clean target
clean:
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 clean
.PHONY : clean
# The main clean target
clean/fast: clean
.PHONY : clean/fast
# Prepare targets for installation.
preinstall: all
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall
# Prepare targets for installation.
preinstall/fast:
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall/fast
# clear depends
depend:
$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
.PHONY : depend
#=============================================================================
# Target rules for targets named a2
# Build rule for target.
a2: cmake_check_build_system
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 a2
.PHONY : a2
# fast build rule for target.
a2/fast:
$(MAKE) $(MAKESILENT) -f CMakeFiles/a2.dir/build.make CMakeFiles/a2.dir/build
.PHONY : a2/fast
lib/advanced_C_standard_library/src/array.o: lib/advanced_C_standard_library/src/array.c.o
.PHONY : lib/advanced_C_standard_library/src/array.o
# target to build an object file
lib/advanced_C_standard_library/src/array.c.o:
$(MAKE) $(MAKESILENT) -f CMakeFiles/a2.dir/build.make CMakeFiles/a2.dir/lib/advanced_C_standard_library/src/array.c.o
.PHONY : lib/advanced_C_standard_library/src/array.c.o
lib/advanced_C_standard_library/src/array.i: lib/advanced_C_standard_library/src/array.c.i
.PHONY : lib/advanced_C_standard_library/src/array.i
# target to preprocess a source file
lib/advanced_C_standard_library/src/array.c.i:
$(MAKE) $(MAKESILENT) -f CMakeFiles/a2.dir/build.make CMakeFiles/a2.dir/lib/advanced_C_standard_library/src/array.c.i
.PHONY : lib/advanced_C_standard_library/src/array.c.i
lib/advanced_C_standard_library/src/array.s: lib/advanced_C_standard_library/src/array.c.s
.PHONY : lib/advanced_C_standard_library/src/array.s
# target to generate assembly for a file
lib/advanced_C_standard_library/src/array.c.s:
$(MAKE) $(MAKESILENT) -f CMakeFiles/a2.dir/build.make CMakeFiles/a2.dir/lib/advanced_C_standard_library/src/array.c.s
.PHONY : lib/advanced_C_standard_library/src/array.c.s
lib/advanced_C_standard_library/src/file.o: lib/advanced_C_standard_library/src/file.c.o
.PHONY : lib/advanced_C_standard_library/src/file.o
# target to build an object file
lib/advanced_C_standard_library/src/file.c.o:
$(MAKE) $(MAKESILENT) -f CMakeFiles/a2.dir/build.make CMakeFiles/a2.dir/lib/advanced_C_standard_library/src/file.c.o
.PHONY : lib/advanced_C_standard_library/src/file.c.o
lib/advanced_C_standard_library/src/file.i: lib/advanced_C_standard_library/src/file.c.i
.PHONY : lib/advanced_C_standard_library/src/file.i
# target to preprocess a source file
lib/advanced_C_standard_library/src/file.c.i:
$(MAKE) $(MAKESILENT) -f CMakeFiles/a2.dir/build.make CMakeFiles/a2.dir/lib/advanced_C_standard_library/src/file.c.i
.PHONY : lib/advanced_C_standard_library/src/file.c.i
lib/advanced_C_standard_library/src/file.s: lib/advanced_C_standard_library/src/file.c.s
.PHONY : lib/advanced_C_standard_library/src/file.s
# target to generate assembly for a file
lib/advanced_C_standard_library/src/file.c.s:
$(MAKE) $(MAKESILENT) -f CMakeFiles/a2.dir/build.make CMakeFiles/a2.dir/lib/advanced_C_standard_library/src/file.c.s
.PHONY : lib/advanced_C_standard_library/src/file.c.s
lib/advanced_C_standard_library/src/hashmap.o: lib/advanced_C_standard_library/src/hashmap.c.o
.PHONY : lib/advanced_C_standard_library/src/hashmap.o
# target to build an object file
lib/advanced_C_standard_library/src/hashmap.c.o:
$(MAKE) $(MAKESILENT) -f CMakeFiles/a2.dir/build.make CMakeFiles/a2.dir/lib/advanced_C_standard_library/src/hashmap.c.o
.PHONY : lib/advanced_C_standard_library/src/hashmap.c.o
lib/advanced_C_standard_library/src/hashmap.i: lib/advanced_C_standard_library/src/hashmap.c.i
.PHONY : lib/advanced_C_standard_library/src/hashmap.i
# target to preprocess a source file
lib/advanced_C_standard_library/src/hashmap.c.i:
$(MAKE) $(MAKESILENT) -f CMakeFiles/a2.dir/build.make CMakeFiles/a2.dir/lib/advanced_C_standard_library/src/hashmap.c.i
.PHONY : lib/advanced_C_standard_library/src/hashmap.c.i
lib/advanced_C_standard_library/src/hashmap.s: lib/advanced_C_standard_library/src/hashmap.c.s
.PHONY : lib/advanced_C_standard_library/src/hashmap.s
# target to generate assembly for a file
lib/advanced_C_standard_library/src/hashmap.c.s:
$(MAKE) $(MAKESILENT) -f CMakeFiles/a2.dir/build.make CMakeFiles/a2.dir/lib/advanced_C_standard_library/src/hashmap.c.s
.PHONY : lib/advanced_C_standard_library/src/hashmap.c.s
src/main.o: src/main.c.o
.PHONY : src/main.o
# target to build an object file
src/main.c.o:
$(MAKE) $(MAKESILENT) -f CMakeFiles/a2.dir/build.make CMakeFiles/a2.dir/src/main.c.o
.PHONY : src/main.c.o
src/main.i: src/main.c.i
.PHONY : src/main.i
# target to preprocess a source file
src/main.c.i:
$(MAKE) $(MAKESILENT) -f CMakeFiles/a2.dir/build.make CMakeFiles/a2.dir/src/main.c.i
.PHONY : src/main.c.i
src/main.s: src/main.c.s
.PHONY : src/main.s
# target to generate assembly for a file
src/main.c.s:
$(MAKE) $(MAKESILENT) -f CMakeFiles/a2.dir/build.make CMakeFiles/a2.dir/src/main.c.s
.PHONY : src/main.c.s
# Help Target
help:
@echo "The following are some of the valid targets for this Makefile:"
@echo "... all (the default if no target is provided)"
@echo "... clean"
@echo "... depend"
@echo "... edit_cache"
@echo "... rebuild_cache"
@echo "... a2"
@echo "... lib/advanced_C_standard_library/src/array.o"
@echo "... lib/advanced_C_standard_library/src/array.i"
@echo "... lib/advanced_C_standard_library/src/array.s"
@echo "... lib/advanced_C_standard_library/src/file.o"
@echo "... lib/advanced_C_standard_library/src/file.i"
@echo "... lib/advanced_C_standard_library/src/file.s"
@echo "... lib/advanced_C_standard_library/src/hashmap.o"
@echo "... lib/advanced_C_standard_library/src/hashmap.i"
@echo "... lib/advanced_C_standard_library/src/hashmap.s"
@echo "... src/main.o"
@echo "... src/main.i"
@echo "... src/main.s"
.PHONY : help
#=============================================================================
# Special targets to cleanup operation of make.
# Special rule to run CMake to check the build system integrity.
# No rule that depends on this can have commands that come from listfiles
# because they might be regenerated.
cmake_check_build_system:
$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
.PHONY : cmake_check_build_system

View File

@ -0,0 +1,54 @@
# Install script for directory: /home/mrgeorgen/dev/bwinf40-runde1/a2-Vollgeladen
# Set the install prefix
if(NOT DEFINED CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX "/usr/local")
endif()
string(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
# Set the install configuration name.
if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
if(BUILD_TYPE)
string(REGEX REPLACE "^[^A-Za-z0-9_]+" ""
CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}")
else()
set(CMAKE_INSTALL_CONFIG_NAME "Debug")
endif()
message(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"")
endif()
# Set the component getting installed.
if(NOT CMAKE_INSTALL_COMPONENT)
if(COMPONENT)
message(STATUS "Install component: \"${COMPONENT}\"")
set(CMAKE_INSTALL_COMPONENT "${COMPONENT}")
else()
set(CMAKE_INSTALL_COMPONENT)
endif()
endif()
# Install shared libraries without execute permission?
if(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)
set(CMAKE_INSTALL_SO_NO_EXE "0")
endif()
# Is this installation the result of a crosscompile?
if(NOT DEFINED CMAKE_CROSSCOMPILING)
set(CMAKE_CROSSCOMPILING "FALSE")
endif()
# Set default install directory permissions.
if(NOT DEFINED CMAKE_OBJDUMP)
set(CMAKE_OBJDUMP "/usr/bin/objdump")
endif()
if(CMAKE_INSTALL_COMPONENT)
set(CMAKE_INSTALL_MANIFEST "install_manifest_${CMAKE_INSTALL_COMPONENT}.txt")
else()
set(CMAKE_INSTALL_MANIFEST "install_manifest.txt")
endif()
string(REPLACE ";" "\n" CMAKE_INSTALL_MANIFEST_CONTENT
"${CMAKE_INSTALL_MANIFEST_FILES}")
file(WRITE "/home/mrgeorgen/dev/bwinf40-runde1/a2-Vollgeladen/${CMAKE_INSTALL_MANIFEST}"
"${CMAKE_INSTALL_MANIFEST_CONTENT}")

View File

@ -0,0 +1,22 @@
[
{
"directory": "/home/mrgeorgen/dev/bwinf40-runde1/a2-Vollgeladen",
"command": "/usr/bin/cc -I/home/mrgeorgen/dev/bwinf40-runde1/a2-Vollgeladen/lib/advanced_C_standard_library/include -g -std=gnu99 -o CMakeFiles/a2.dir/src/main.c.o -c /home/mrgeorgen/dev/bwinf40-runde1/a2-Vollgeladen/src/main.c",
"file": "/home/mrgeorgen/dev/bwinf40-runde1/a2-Vollgeladen/src/main.c"
},
{
"directory": "/home/mrgeorgen/dev/bwinf40-runde1/a2-Vollgeladen",
"command": "/usr/bin/cc -I/home/mrgeorgen/dev/bwinf40-runde1/a2-Vollgeladen/lib/advanced_C_standard_library/include -g -std=gnu99 -o CMakeFiles/a2.dir/lib/advanced_C_standard_library/src/array.c.o -c /home/mrgeorgen/dev/bwinf40-runde1/a2-Vollgeladen/lib/advanced_C_standard_library/src/array.c",
"file": "/home/mrgeorgen/dev/bwinf40-runde1/a2-Vollgeladen/lib/advanced_C_standard_library/src/array.c"
},
{
"directory": "/home/mrgeorgen/dev/bwinf40-runde1/a2-Vollgeladen",
"command": "/usr/bin/cc -I/home/mrgeorgen/dev/bwinf40-runde1/a2-Vollgeladen/lib/advanced_C_standard_library/include -g -std=gnu99 -o CMakeFiles/a2.dir/lib/advanced_C_standard_library/src/file.c.o -c /home/mrgeorgen/dev/bwinf40-runde1/a2-Vollgeladen/lib/advanced_C_standard_library/src/file.c",
"file": "/home/mrgeorgen/dev/bwinf40-runde1/a2-Vollgeladen/lib/advanced_C_standard_library/src/file.c"
},
{
"directory": "/home/mrgeorgen/dev/bwinf40-runde1/a2-Vollgeladen",
"command": "/usr/bin/cc -I/home/mrgeorgen/dev/bwinf40-runde1/a2-Vollgeladen/lib/advanced_C_standard_library/include -g -std=gnu99 -o CMakeFiles/a2.dir/lib/advanced_C_standard_library/src/hashmap.c.o -c /home/mrgeorgen/dev/bwinf40-runde1/a2-Vollgeladen/lib/advanced_C_standard_library/src/hashmap.c",
"file": "/home/mrgeorgen/dev/bwinf40-runde1/a2-Vollgeladen/lib/advanced_C_standard_library/src/hashmap.c"
}
]

82
a2-Vollgeladen/src/main.c Normal file
View File

@ -0,0 +1,82 @@
#include <stdio.h>
#include <acl/file.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#define panicio {\
perror(*filepath);\
return 1;\
}
#define getNumber strtol(nextnumber + 1, &nextnumber, 10)
struct hotel {
uint_least16_t minutes;
uint_least8_t rating;
};
int compareReverse(const void *a, const void *b) {
return (uint_least8_t*)a - (uint_least8_t*)b;
}
int main(int argc, char *argv[]) {
for(char **filepath = argv + 1; filepath - argv < argc; ++filepath) {
printf("%s:\n", *filepath);
uint_least16_t numberHotels, totalMinutes;
struct hotel *hotels;
uint_least8_t *ratings;
{
char *inputText;
{
FILE *inputFile = fopen(*filepath, "rb");
if(inputFile == NULL) panicio;
bool success;
inputText = acl_ReadTextFile(inputFile, &success);
if(!success) panicio;
fclose(inputFile);
}
{
char *nextnumber;
numberHotels = strtol(inputText, &nextnumber, 10);
totalMinutes = getNumber;
hotels = malloc(numberHotels * sizeof *hotels + numberHotels * sizeof *ratings);
ratings = (uint_least8_t*)(hotels + numberHotels);
for(uint_least16_t i = 0; i < numberHotels; ++i) {
hotels[i].minutes = getNumber;
ratings[i] = 10 * getNumber;
ratings[i] += getNumber;
hotels[i].rating = ratings[i];
}
}
free(inputText);
}
qsort(ratings, numberHotels, sizeof *ratings, compareReverse);
{
struct hotel hotelRoute[4];
uint_least8_t stoppedHotels;
{
uint_least8_t *rating = ratings;
do {
uint_least16_t lastHotelMinutes = 0;
struct hotel *possibleStop = NULL;
stoppedHotels = 0;
for(struct hotel *currentHotel = hotels; currentHotel - hotels < numberHotels; ++currentHotel) {
if(currentHotel->minutes - lastHotelMinutes > 360 && possibleStop != NULL) {
if(stoppedHotels >= 4) break;
hotelRoute[stoppedHotels] = *possibleStop;
lastHotelMinutes = possibleStop->minutes;
currentHotel = possibleStop;
++stoppedHotels;
}
if(currentHotel->rating >= *rating) possibleStop = currentHotel;
}
++rating;
} while(totalMinutes - hotelRoute[stoppedHotels - 1].minutes > 360);
}
for(struct hotel *hotelPrint = hotelRoute; hotelPrint - hotelRoute < stoppedHotels; ++hotelPrint) {
printf("Hotel: %" PRIuLEAST16 " m, rating: %" PRIuLEAST8 "\n", hotelPrint->minutes, hotelPrint->rating);
}
}
free(hotels);
}
}