Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //setul 1 problema 1
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- //Se citesc datele despre elevii unei clase, respectiv numele şi data naşterii. Să se ordoneze elevii în ordinea crescătoare după data naşterii şi să se afişeze această situaţie
- typedef struct data
- {
- int zi, luna, an;
- } Data;
- typedef struct elev
- {
- char nume[20];
- Data datan;
- } Elev;
- typedef struct vector{
- int current_dim;
- int total_dim;
- Elev* elevi;
- } Vector;
- void init_vector(Vector* vector, int dim)
- {
- vector->current_dim = 0;
- vector->total_dim = dim;
- vector->elevi = (Elev*) malloc(sizeof(Elev) * dim);
- }
- void add_vector(Vector* v_elevi, Elev elev)
- {
- if(v_elevi->current_dim >= v_elevi->total_dim) {
- v_elevi->total_dim = v_elevi->total_dim * 2;
- v_elevi->elevi =
- (Elev*) realloc(v_elevi->elevi, sizeof(Elev) * v_elevi->total_dim);
- }
- strcpy(v_elevi->elevi[v_elevi->current_dim].nume, elev.nume);
- v_elevi->elevi[v_elevi->current_dim].datan.zi = elev.datan.zi;
- v_elevi->elevi[v_elevi->current_dim].datan.luna = elev.datan.luna;
- v_elevi->elevi[v_elevi->current_dim].datan.an = elev.datan.an;
- v_elevi->current_dim++;
- }
- void print_elevi(Vector v_elevi)
- {
- for(int i = 0; i < v_elevi.current_dim; i++) {
- printf("Nume: %s\tAn: %d\tZi: %d\n", v_elevi.elevi[i].nume, v_elevi.elevi[i].datan.an,
- v_elevi.elevi[i].datan.zi);
- }
- }
- void sort_elevi(Elev* e, int n)
- {
- int i,j;
- Elev aux;
- for (i = 0; i < n; i++)
- for (j = i + 1; j <= n; j++)
- {
- if (e[i].datan.an > e[j].datan.an)
- {
- aux = e[i];
- e[i] = e[j];
- e[j] = aux;
- }
- else if (e[i].datan.an == e[j].datan.an)
- {
- if (e[i].datan.luna > e[j].datan.luna)
- {
- aux = e[i];
- e[i] = e[j];
- e[j] = aux;
- }
- else if (e[i].datan.luna == e[j].datan.luna)
- if (e[i].datan.zi > e[j].datan.zi)
- {
- aux = e[i];
- e[i] = e[j];
- e[j] = aux;
- }
- }
- }
- }
- int
- main ()
- {
- int n, i;
- Vector v_elevi;
- Elev aux;
- printf ("Numarul de elevi:");
- scanf ("%d", &n);
- init_vector(&v_elevi, 1);
- for (i = 0; i < n; i++)
- {
- scanf("%s %d %d %d", aux.nume, &aux.datan.an, &aux.datan.luna, &aux.datan.zi);
- add_vector(&v_elevi, aux);
- }
- //sort_elevi(v_elevi.elevi, v_elevi.current_dim);
- print_elevi(v_elevi);
- return 0;
- }
- // //setul 9 problema 2
- // #include<stdio.h>
- // int main ()
- // {
- // struct firma
- //
- // {
- //
- // int cod_firma;
- //
- // int cod_produs;
- //
- // float cant;
- // }v[4], x;
- //
- //
- //
- //
- // int i,n,j ;
- //
- // printf("Dati numarul n:");
- //
- // scanf("%d", &n);
- //
- // for(i=1;i<n;i++)
- //
- // {
- //
- // printf("Firma %d\n", i);
- //
- // scanf("%d", v[i].cod_firma);
- //
- // printf("produsul \n ");
- //
- // scanf("%d",&v[i].cod_produs);
- //
- // printf("cantitate \n");
- //
- // scanf("%f",&v[i].cant);
- //
- //
- // }
- // for(i=1;i<n;i++)
- //
- // for (j=i+1;j<=n;j++)
- //
- // if(v[i].cant>v[j].cant)
- //
- // {
- //
- // x=v[i];
- //
- // v[i]=v[j];
- //
- // v[j]=x;
- //
- // }
- //
- // for(i=1;i<n;i++)
- //
- // printf(" %d %f", v[i].cod_firma,v[i].cant);
- //
- // return 0;
- //
- // }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement