ProgMe

Task 4

Mar 27th, 2020
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. bool repid(int i)
  6. {
  7.     string s;
  8.     int ostatok;
  9.     while(i > 0)
  10.     {
  11.         ostatok = i % 3;
  12.         i /= 3;
  13.         s += to_string(ostatok);
  14.     }
  15.     bool ans = 1;
  16.     for (int i = 1; i < s.size(); i++)
  17.     {
  18.         if (s [i] != s [i - 1])
  19.             ans = 0;
  20.     }
  21.     return ans;
  22. }
  23.  
  24. int main()
  25. {
  26.     int l, r;
  27.     cin >> l >> r;
  28.     int minans = -1, maxans = -1;
  29.     for (int i = l; i <= r; i++)
  30.     {
  31.         if (repid(i))
  32.         {
  33.             maxans = i;
  34.             if (minans == -1)
  35.                 minans = i;
  36.         }
  37.     }
  38.     cout << minans << " " << maxans;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment