Advertisement
JosepRivaille

P37257: Funció per a tres dígits iguals consecutius

Apr 4th, 2015
707
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.37 KB | None | 0 0
  1. //Retorna true si n expressat en base b té tres dígits seguits iguals
  2. bool tres_digits_seguits_iguals(int n, int b) {
  3.     if (n < b*b) return false;
  4.     else {
  5.         int mod1 = n%b;
  6.         int mod2 = (n/b)%b;
  7.         int mod3 = (n/(b*b))%b;
  8.         if (mod1 == mod2 and mod1 == mod3) return true;
  9.         else return tres_digits_seguits_iguals(n/b, b);
  10.     }
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement