amermo

da li broj ima istih cifara - preko vektora

Feb 27th, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. bool iste_cifre(int broj)
  5. {
  6.     std::vector<int> brojaci(10);
  7.     int a(broj);
  8.     while(a > 0)
  9.     {
  10.         brojaci[a%10]++;
  11.         a/=10;
  12.     }
  13.     for(int i(0); i < brojaci.size(); i++)
  14.     {
  15.         if(brojaci[i] > 1)
  16.             return true;
  17.     }
  18.     return false;
  19. }
  20.  
  21.  
  22. int main()
  23. {
  24.     int n;
  25.     std::cout << "Unesite neki broj: " << std::endl;
  26.     std::cin >> n;
  27.     if(iste_cifre(n))
  28.         std::cout << "Broj ima istih cifara!" << std::endl;
  29.     else
  30.         std::cout << "Broj nema istih cifara!" << std::endl;
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment