Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct NOD{
- char nume[30];
- struct NOD *next;
- }NOD;
- NOD *creare_nod(char *s){
- NOD *nod_nou = malloc(sizeof(NOD));
- strcpy(nod_nou->nume, s);
- nod_nou -> next = NULL;
- return nod_nou;
- }
- NOD *adauga_nod(NOD *head, char *s){
- NOD *nr_nou = creare_nod(s), *nod = head;
- if(head == NULL)
- return nr_nou;
- while(nod->next) nod = nod-> next;
- nod -> next = nr_nou;
- return head;
- }
- void afisare_lista(NOD *head){
- NOD *nod = head;
- for(; nod; nod = nod->next)
- printf("%s\n", nod->nume);
- }
- int intersect(NOD *head1, NOD *head2){
- int nr = 0;
- for(NOD *nod1 = head1; nod1; nod1 = nod1 -> next)
- for(NOD *nod2 = head2; nod2; nod2 = nod2 -> next)
- if(strcmp(nod1->nume, nod2->nume) == 0){
- nr++;
- break;
- }
- return nr;
- }
- int main() {
- int n;
- char s[30];
- NOD *lista_cumparaturi = NULL, *lista_furnizor = NULL;
- scanf("%d", &n);
- for (int i = 0; i < n; i++) {
- scanf("%s", s);
- lista_cumparaturi = adauga_nod(lista_cumparaturi, s);
- }
- while (scanf("%s", s) != EOF) {
- lista_furnizor = adauga_nod(lista_furnizor, s);
- }
- int nr_produse = intersect(lista_cumparaturi, lista_furnizor);
- printf("%d\n", nr_produse);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement