Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- //pre: 0 < n and n < 10^9
- //post: returns true if n is a triplets-number and false otherwise
- bool triplet_number(int n){
- if (n < 100) return false;
- else if (n < 1000) {
- int x = n % 10;
- int y = (n / 10) % 10;
- int z = (n / 100) % 10;
- return x == y and y == z;
- }
- else return triplet_number(n / 1000) and (triplet_number(n % 1000) or n%1000 == 0);
- }
- int main(){
- int n;
- while (cin >> n){
- if (triplet_number(n)) cout << "TRUE" << endl;
- else cout << "FALSE" << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement