Advertisement
Weird_Thing

Triplet Numbers - X99068

Nov 14th, 2019
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. //pre: 0 < n and n < 10^9
  5. //post: returns true if n is a triplets-number and false otherwise
  6. bool triplet_number(int n){
  7.   if (n < 100) return false;
  8.   else if (n < 1000) {
  9.     int x = n % 10;
  10.     int y = (n / 10) % 10;
  11.     int z = (n / 100) % 10;
  12.     return x == y and y == z;
  13.   }
  14.   else return triplet_number(n / 1000) and (triplet_number(n % 1000) or n%1000 == 0);
  15. }
  16.  
  17. int main(){
  18.   int n;
  19.   while (cin >> n){
  20.     if (triplet_number(n)) cout << "TRUE" << endl;
  21.     else cout << "FALSE" << endl;
  22.   }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement