BORUTO-121

DeleteSameNumbers

Sep 19th, 2021 (edited)
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.69 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int unesi_niz(int *niz, int KAP){
  4.     int *pok;
  5.     int broj,i;
  6.     for(pok=niz,i=0;(pok-niz)<KAP;pok++,i++){
  7.         scanf("%d",&broj);
  8.         if(broj==-1)break;
  9.         *pok=broj;
  10.        }
  11.     return i;
  12. }
  13.  
  14. int jel_imaju_iste_cifre(int broj, int provjera){
  15.   if(provjera>broj){
  16.     int zamjena=provjera;
  17.     provjera=broj;
  18.     broj=zamjena;
  19.   }
  20.     int i=0, brojac=0;
  21.     do{
  22.         int cifra=broj%10;
  23.         int pomoc=provjera;
  24.         do{
  25.             int helpCifra = pomoc%10;
  26.             if(helpCifra == cifra){
  27.             brojac++; break;
  28.             }
  29.             pomoc/=10;
  30.         }while(pomoc);
  31.         broj/=10;
  32.         i++;
  33.     }while(broj);
  34.    return i==brojac;
  35. }
  36.  
  37. int izbaci_iste_cifre(int *pocA, int velA, int *pocB, int velB){
  38.     int *pomocA;
  39.     int *pomocB=pocB;
  40.     for(;pocB!=pomocB+velB;pocB++){
  41.         int nasao=0;
  42.         for(pomocA=pocA;pomocA!=pocA+velA; pomocA++)
  43.         if(jel_imaju_iste_cifre(*pomocA,*pocB)){
  44.             nasao=1;
  45.             break;
  46.         }
  47.  
  48.         if(nasao){
  49.             int *pomoc1=pocB, *pomoc2=pocB+1;
  50.             for(;pomoc1!=pomocB+velB-1;pomoc1++,pomoc2++)
  51.             *pomoc1=*pomoc2;
  52.           velB--;
  53.           pocB--;
  54.         }
  55.     }
  56.   return velB;
  57. }
  58.  
  59. void ispisi_niz(int *pocetak, int *kraj){
  60.     int *pok;
  61.     for(pok=pocetak;pok!=kraj-1;pok++)
  62.        printf("%d,",*pok);
  63.     printf("%d.",*pok);
  64. }
  65.  
  66. int main() {
  67.     int nizA[100],nizB[100];
  68.     printf("Unesite niz A: ");
  69.     int velA=unesi_niz(nizA,100);
  70.     printf("Unesite niz B: ");
  71.     int velB=unesi_niz(nizB,100);
  72.     velB=izbaci_iste_cifre(nizA,velA,nizB,velB);
  73.     ispisi_niz(nizB,nizB+velB);
  74.     return 0;
  75. }
  76.  
Add Comment
Please, Sign In to add comment