Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct NOD{
- int nr;
- struct NOD *next;
- }NOD;
- NOD *creare_nod(int nr){
- NOD *nod_nou = malloc(sizeof(NOD));
- nod_nou -> nr = nr;
- nod_nou -> next = NULL;
- return nod_nou;
- }
- NOD *adauga_numar(NOD *head, int nr){
- NOD *nr_nou = creare_nod(nr), *nod = head;
- if(head == NULL)
- return nr_nou;
- if(head -> nr > nr){
- nr_nou -> next = head;
- return nr_nou;
- }
- while(nod->next && nod ->next ->nr < nr) nod = nod-> next;
- nr_nou -> next = nod->next;
- nod -> next = nr_nou;
- return head;
- }
- void afisare_lista(NOD *head){
- NOD *nod = head;
- for(; nod; nod = nod->next)
- printf("%d ", nod->nr);
- }
- struct NOD *sterge_nod(NOD *head, NOD *sters){
- NOD *nod = head;
- if(head == sters){
- head = head -> next;
- free(sters);
- return head;
- }
- for(; nod -> next != sters; nod = nod -> next);
- nod -> next = nod -> next -> next;
- free(sters);
- return head;
- }
- NOD *diferenta(NOD *head1, NOD *head2){
- for(NOD *nod2 = head2; nod2; nod2 = nod2 -> next)
- for(NOD *nod1 = head1; nod1; nod1 = nod1 ->next)
- if(nod1 -> nr == nod2 -> nr){
- head1 = sterge_nod(head1, nod1);
- break;
- }
- return head1;
- }
- int main(){
- int n, numar;
- NOD *bunica, *numere;
- scanf("%d", &n);
- for(int i = 0; i< n*n; i++){
- scanf("%d", &numar);
- bunica = adauga_numar(bunica, numar);
- }
- while(scanf("%d", &numar) != EOF){
- numere = adauga_numar(numere, numar);
- }
- bunica = diferenta(bunica, numere);
- if(bunica == NULL)
- printf("BINGO!");
- else
- afisare_lista(bunica);
- return 0;
- }
Add Comment
Please, Sign In to add comment