Skip to content

Commit

Permalink
Add more solutions.
Browse files Browse the repository at this point in the history
  • Loading branch information
stopnoanime committed Nov 11, 2023
1 parent 7f026d7 commit 8f6b559
Show file tree
Hide file tree
Showing 15 changed files with 177 additions and 2 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:

Expand Down
42 changes: 42 additions & 0 deletions src/cw3/zad16/diff_seq_fam.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <stdio.h>
#include <stdlib.h>

//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));
}
51 changes: 51 additions & 0 deletions src/cw3/zad17/diff_diff_seq_fam.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <stdio.h>
#include <stdlib.h>

//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));
}
59 changes: 59 additions & 0 deletions src/cw5/zad17/orzechy.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include <stdio.h>
#include <stdlib.h>

#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));
}
2 changes: 1 addition & 1 deletion src/kol1_22/zad1/schodki.c
Original file line number Diff line number Diff line change
Expand Up @@ -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<n; i++) {
Expand Down
1 change: 1 addition & 0 deletions tests/cw3/zad16/c/diff_seq_fam0.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5 1 1 1 1 1
1 change: 1 addition & 0 deletions tests/cw3/zad16/c/diff_seq_fam0.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.000000 0.000000 0.000000 0.000000
1 change: 1 addition & 0 deletions tests/cw3/zad16/c/diff_seq_fam1.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6 1 2 3 4 5 6
1 change: 1 addition & 0 deletions tests/cw3/zad16/c/diff_seq_fam1.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.000000 1.000000 1.000000 1.000000 1.000000
1 change: 1 addition & 0 deletions tests/cw3/zad16/c/diff_seq_fam2.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10 1 6 -3 2 10 12 3 5 24 0
1 change: 1 addition & 0 deletions tests/cw3/zad16/c/diff_seq_fam2.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.000000 -9.000000 5.000000 8.000000 2.000000 -9.000000 2.000000 19.000000 -24.000000
1 change: 1 addition & 0 deletions tests/cw3/zad17/c/diff_diff_seq_fam0.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4 1 2 4 7
4 changes: 4 additions & 0 deletions tests/cw3/zad17/c/diff_diff_seq_fam0.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
1.000000 2.000000 4.000000 7.000000
1.000000 2.000000 3.000000
1.000000 1.000000
0.000000
6 changes: 6 additions & 0 deletions tests/cw5/zad17/c/orzechy0.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
0 0 4 1 2 0
3 3 8 11 3 2
1 3 9 8 1 2
2 1 1 2 0 12

6
1 change: 1 addition & 0 deletions tests/cw5/zad17/c/orzechy0.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
42

0 comments on commit 8f6b559

Please sign in to comment.