Pentru fisierele sursa cu rezolvarile, verificati arhiva.
/*
 * Problema 2
 *
 */

#include <stdio.h>
#include <time.h>

int main()
{
        time_t t1;
        struct tm *t2;
        time(&t1);
        t2 = localtime(&t1);
        printf("%s%s", ctime(&t1), asctime(t2));
        return 0;
}


/*
 * Problema 3
 *
 */

#include <stdio.h>
#include <time.h>

char *timestr(struct tm t, char *time)
{
        //sprintf(time, "%02d:%02d:%02d\n", t.tm_hour, t.tm_min, t.tm_sec);
        printf("%02d:%02d:%02d\n", t.tm_hour, t.tm_min, t.tm_sec);
        return time;
}

int main()
{
        time_t t1;
        struct tm *t2;
        char buffer[100];
        time(&t1);
        t2 = localtime(&t1);
        printf("%s", timestr(*t2, buffer));
        return 0;
}


/*
 * Problema 4
 *
 */

#include <stdio.h>
#include <stdlib.h>

typedef struct vector {
        int *v;
        int cap;
        int n;
} vector;

void init_vector(vector *a, int nr)
{
        a->cap = nr;
        a->n = 0;
        a->v = (int*) malloc (nr * sizeof(int));
}

void adauga_vector(vector *a, int n)
{
        if (a->cap == a->n) {
                a->cap *= 2;
                a->v = (int*) realloc (a->v, a->cap * sizeof(int));
        }
        a->v[a->n] = n;
        a->n++;
}

void scrie_vector(vector *a)
{
        int i;
        for (i = 0; i < a->n; i++)
                printf("%d ", a->v[i]);
        printf("\n");
}

int main()
{
        vector v;
        int i;
        init_vector(&v, 10);
        for (i = 0; i < 20; i++)
                adauga_vector(&v, i);
        scrie_vector(&v);
        return 0;
}


/*
 * Problema 5
 *
 */

#include <stdio.h>

#define NMAX 100

typedef struct complex {
        float re, im;
} complex;

complex adunare(complex a, complex b)
{
        complex c;
        c.re = a.re + b.re;
        c.im = a.im + b.im;
        return c;
}

complex scadere(complex a, complex b)
{
        complex c;
        c.re = a.re - b.re;
        c.im = a.im - b.im;
        return c;
}

complex inmultire(complex a, complex b)
{
        complex c;
        c.re = a.re * b.re - a.im * b.im;
        c.im = a.im * b.re + a.re * b.im;
        return c;
}

complex putere(complex a, int putere)
{
        complex c;
        int i;
        c.re = 1;
        c.im = 0;
        for (i = 0; i < putere; i++)
                c = inmultire(c, a);
        return c;
}

void scrie(complex a)
{
        printf("(%.2f, %.2f)\n", a.re, a.im);
}

int main()
{
        int n, i;
        float c[NMAX];
        complex x, p, aux;

        printf("Gradul: ");
        scanf("%d", &n);
        printf("Cei n+1 coeficienti: ");
        for (i = 0; i <= n; i++)
                scanf("%f", &c[i]);

        printf("x.re = ");
        scanf("%f", &x.re);
        printf("x.im = ");
        scanf("%f", &x.im);

        p.re = p.im = 0;

        for (i = 0; i <= n; i++) {
                aux.re = c[i];
                aux.im = 0;
                p = adunare(p, inmultire(aux, putere(x, i)));
        }
        scrie(p);
        return 0;
}


/*
 * Problema 6
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct Pereche {
        char *cuv;
        int ap;
} Pereche;

int find(Pereche **vec, int n, char *cuv)
{
        int i;
        for (i = 0; i < n; i++)
                if (strcmp(vec[i]->cuv, cuv) == 0)
                        return i;
        return -1;
}

Pereche *newPereche(char *a)
{
        Pereche *p = (Pereche*) malloc (sizeof(Pereche));
        p->cuv = strdup(a);
        p->ap = 1;
        return p;
}

int main()
{
        int i, idx, n, nd = 0, cap = 4;
        char cuv[1000];
        Pereche **vec;
        int *ap;

        printf("n = ");
        scanf("%d", &n);

        /* initializare vectori */
        vec = (Pereche**) malloc (cap * sizeof(Pereche*));

        for (i = 0; i < n; i++) {
                scanf("%s", cuv);
                idx = find(vec, nd, cuv);

                if (idx != -1)
                        vec[idx]->ap++;
                else {

                        if (cap == nd) {
                                /* realocare */
                                cap *= 2;
                                vec = (Pereche**) realloc (vec, cap * sizeof(Pereche*));
                        }

                        /* adaugare la vector */
                vec[nd] = newPereche(cuv);
                nd++;
                }
        }
        
        /* afisare rezultat */
        for (i = 0; i < nd; i++)
                printf("%s %d\n", vec[i]->cuv,vec[i]->ap);

        /* eliberare memorie */
        for (i = 0; i < nd; i++) {
                free(vec[i]->cuv);
                free(vec[i]);
        }
        free(vec);

        return 0;
}