Kaidul

All different digit

May 15th, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.22 KB | None | 0 0
  1. bool alldiff(int n) {
  2.     int c, mask = 0;
  3.     for (int i = 0; i < 5; i++) {
  4.         c = (int) (n / pow(10, i)) % 10;
  5.         if ((mask >> c) % 2)
  6.             return false;
  7.         mask |= 1 << c;
  8.     }
  9.     return true;
  10. }
Advertisement
Add Comment
Please, Sign In to add comment