Advertisement
Andrei11114

Untitled

Mar 12th, 2014
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. long getNumWithXZero(long n)    //creaza un numar ce este egal cu 1 urmat atatea zerouri cate cifre are numarul:
  2. {                               //Ex : 665 = 3 cifre =>  1 000 (1 + 3 zerouri dupa)
  3.     if(n == 0)
  4.         return 1;
  5.     return 10 * getNumWithXZero(n / 10);
  6. }
  7.  
  8. bool checkNumForSucc(long n, int succNum)   //cauta in N pe succNum
  9. {
  10.     long divNum = getNumWithXZero(succNum);
  11.  
  12.     while(n)
  13.     {
  14.         if(n%divNum == succNum)
  15.             return true;
  16.  
  17.         n/=10;
  18.     }
  19.     return false;
  20. }
  21.  
  22. void Probl3(long arrayNumbers[], int succNum, int arrayLen) //parcuge vectorul si afiseaza rezultatele
  23. {
  24.     for(int i = 0 ; i < arrayLen ; i++ )
  25.         if(checkNumForSucc(arrayNumbers[i], succNum))
  26.             cout << arrayNumbers[i] << endl;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement