diff --git a/README.md b/README.md index 4571d6d..1958668 100644 --- a/README.md +++ b/README.md @@ -71,9 +71,12 @@ _WDP\* MIM UW_ - [next_perm](./src/cw3/zad12/next_perm.c): autor: @lbozyk (C) :white_check_mark: - [zad. 14.] sprawdź, czy jeden ciąg zawiera się w drugim - [subsequence](./src/cw3/zad14/subsequence.c) (C) :white_check_mark::microscope: -- [zad. 16.] ciąg róznicowy +- [zad. 16.] ciąg różnicowy - [differential_sequence](./src/cw3/zad16/differential_sequence.c) (C) - [diff_seq](./src/cw3/zad16/diff_seq.c) (C): autor: @lbozyk (C) :white_check_mark: + - [diff_seq_fam](./src/cw3/zad16/diff_seq_fam.c) (C) :white_check_mark::microscope: +- [zad. 17.] ciąg ciągu różnicowego + - [diff_diff_seq_fam](./src/cw3/zad17/diff_diff_seq_fam.c) (C) :white_check_mark::microscope: ### Laboratorium II: [Gra w skakanie (NWD)](./pdf/WDP_.Inf.23_24Z__Zadanie_rozgrzewkowe_2.pdf) 2023.10.11 @@ -130,6 +133,8 @@ _WDP\* MIM UW_ - [zad. 15.] - [zad_15](./src/cw5/zad15/zad_ms.c): autor: @MrD4rkne (C) :white_check_mark::microscope: - [zad15](./src/cw5/zad15/zad15.c): autor: @pixelkubek (C) :white_check_mark: +- [zad. 17.] + - [orzechy](./src/cw5/zad17/orzechy.c) (C) :white_check_mark::microscope: - [zad. 18.] - [zad18](./src/cw5/Zad18/zad18.c): autor: @pixelkubek (C) :white_check_mark: diff --git a/src/cw3/zad16/diff_seq_fam.c b/src/cw3/zad16/diff_seq_fam.c new file mode 100644 index 0000000..075721e --- /dev/null +++ b/src/cw3/zad16/diff_seq_fam.c @@ -0,0 +1,42 @@ +#include +#include + +//Uses https://en.wikipedia.org/wiki/Flexible_array_member at end of struct +typedef struct { + int dl; + double el[]; +} ciag; + +ciag *roznicowy(ciag *c) { + ciag *r = malloc(sizeof(ciag) + (size_t)(c->dl - 1) * sizeof(double)); + r->dl = c->dl - 1; + + for (int i = 0; i < r->dl; i++) + r->el[i] = c->el[i + 1] - c->el[i]; + + return r; +} + +ciag *readCiag() { + int dl; + if(!scanf("%d", &dl)) printf("wrong input"); + + ciag *c = malloc(sizeof(ciag) + (size_t)dl * sizeof(double)); + c->dl = dl; + + for (int i = 0; i < dl; i++) + if(!scanf("%lf", &(c->el[i]))) printf("wrong input"); + + return c; +} + +void printCiag(ciag *c) { + for (int i = 0; i < c->dl; i++) + printf("%lf ", c->el[i]); +} + +int main() { + ciag *c = readCiag(); + + printCiag(roznicowy(c)); +} \ No newline at end of file diff --git a/src/cw3/zad17/diff_diff_seq_fam.c b/src/cw3/zad17/diff_diff_seq_fam.c new file mode 100644 index 0000000..cf8a895 --- /dev/null +++ b/src/cw3/zad17/diff_diff_seq_fam.c @@ -0,0 +1,51 @@ +#include +#include + +//Uses https://en.wikipedia.org/wiki/Flexible_array_member at end of struct +typedef struct ciag { + int dl; + struct ciag *next; + double el[]; +} ciag; + +ciag *roznicowyRec(ciag *c) { + c->next = malloc(sizeof(ciag) + (size_t)(c->dl - 1) * sizeof(double)); + c->next->dl = c->dl - 1; + c->next->next = NULL; + + for (int i = 0; i < c->next->dl; i++) + c->next->el[i] = c->el[i + 1] - c->el[i]; + + if(c->next->dl != 0) roznicowyRec(c->next); + + return c; +} + +ciag *readCiag() { + int dl; + if(!scanf("%d", &dl)) printf("wrong input"); + + ciag *c = malloc(sizeof(ciag) + (size_t)dl * sizeof(double)); + c->dl = dl; + c->next = NULL; + + for (int i = 0; i < dl; i++) + if(!scanf("%lf", &(c->el[i]))) printf("wrong input"); + + return c; +} + +void printCiag(ciag *c) { + for (int i = 0; i < c->dl; i++) + printf("%lf ", c->el[i]); + + printf("\n"); + + if(c->next != NULL) printCiag(c->next); +} + +int main() { + ciag *c = readCiag(); + + printCiag(roznicowyRec(c)); +} \ No newline at end of file diff --git a/src/cw5/zad17/orzechy.c b/src/cw5/zad17/orzechy.c new file mode 100644 index 0000000..dde48b2 --- /dev/null +++ b/src/cw5/zad17/orzechy.c @@ -0,0 +1,59 @@ +#include +#include + +#define x_size 6 +#define y_size 4 + +int orzechy(int a[x_size][y_size], int k) { + int sumPref[x_size + 1][y_size + 1]; + + //Obliczanie sumy prefiksowej + for (int y = 0; y < y_size + 1; y++) { + for (int x = 0; x < x_size + 1; x++) { + if (x == 0 || y == 0) { + sumPref[x][y] = 0; + } else { + sumPref[x][y] = a[x - 1][y - 1] + sumPref[x - 1][y] + + sumPref[x][y - 1] - sumPref[x - 1][y - 1]; + } + } + } + + int maks = 0; + + //Sprawdzanie wszystkich prostokątów zaczynających się w x i y + for (int x = 0; x < x_size; x++) { + for (int y = 0; y < y_size; y++) { + for (int w = 1; w <= k && x + w <= x_size; w++) { + if (k % w != 0) + continue; + + int h = k / w; + + if (y + h > y_size) + continue; + + int suma = sumPref[x + w][y + h] - sumPref[x][y + h] - + sumPref[x + w][y] + sumPref[x][y]; + + if (suma > maks) + maks = suma; + } + } + } + + return maks; +} + +int main() { + int k; + int t[x_size][y_size]; + + for (int y = 0; y < y_size; y++) + for (int x = 0; x < x_size; x++) + if(!scanf("%d", &t[x][y])) printf("wrong input"); + + if(!scanf("%d", &k)) printf("wrong input"); + + printf("%d", orzechy(t, k)); +} \ No newline at end of file diff --git a/src/kol1_22/zad1/schodki.c b/src/kol1_22/zad1/schodki.c index db8f9da..a3d3978 100644 --- a/src/kol1_22/zad1/schodki.c +++ b/src/kol1_22/zad1/schodki.c @@ -5,7 +5,7 @@ // M(n) int schodki(int n, int t[]) { - int *pom = (int*)malloc((size_t)(n+1)*sizeof(int)); + int *pom = (int*)calloc((size_t)(n+1), sizeof(int)); int ile = 0; for(int i=0; i