Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <gsl/gsl_matrix.h>
- #include <gsl/gsl_vector.h>
- int main() {
- int K, L;
- scanf("%d%d", &K, &L); // vnesuvanje na dimenziite od matricata
- int n;
- scanf("%d", &n); // dolzina na vektor
- gsl_vector * vekt = gsl_vector_alloc(n + 10);
- for(int i = 0; i < n; i++) {
- int pom;
- scanf("%d", &pom);
- gsl_vector_set(vekt, i, pom);
- }
- int Z; // kolku treba da skokame
- scanf("%d", &Z);
- gsl_matrix * mat = gsl_matrix_alloc(K, L);
- gsl_matrix_set_zero(mat); // site elementi na matricata na pocetok neka bidat ednakvi na 0
- int mat_i = 0;
- int mat_j = 0;
- for(int i = 0; i < n; i += Z) {
- int max_element = 0;
- for(int j = 0; j < Z; j++) {
- if(i + j < n) {
- if(max_element < gsl_vector_get(vekt, i + j)) {
- max_element = gsl_vector_get(vekt, i + j);
- }
- }
- }
- // printf("%d ", max_element);
- gsl_matrix_set(mat, mat_i, mat_j, (double) max_element);
- mat_j++;
- if(mat_j == L) {
- mat_j = 0;
- mat_i++;
- }
- }
- for(int i = 0; i < K; i++) {
- for(int j = 0; j < L; j++) {
- printf("%.0f ", gsl_matrix_get(mat, i, j));
- }
- printf("\n");
- }
- return 0;
- }
- /*
- 3 3
- 20
- 1 7 0 2 15 3 14 8 9 -2 -3 6 13 0 5 26 12 3 4 7
- 3
- **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement