Advertisement
Taraxacum

Sisyphus

Oct 8th, 2018
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void sisyphus1(int stone)
  6. {
  7.     int sisyphus = stone;
  8.     do {
  9.         cout << sisyphus << endl;
  10.  
  11.         stone = sisyphus;
  12.  
  13.         int digits[10] = { 0 };
  14.         int cnt = 0;
  15.         while (sisyphus > 0) {
  16.             digits[cnt++] = sisyphus % 10;
  17.             sisyphus /= 10;
  18.         }
  19.  
  20.         int even = 0, odd = 0;
  21.         for (int i = 0; i < cnt; i++) {
  22.             if (digits[i] % 2 == 0) {
  23.                 even++;
  24.             } else {
  25.                 odd++;
  26.             }
  27.         }
  28.  
  29.         sisyphus = even * 100 + odd * 10 + cnt;
  30.     } while (sisyphus != stone);
  31. }
  32.  
  33. void sisyphus2(int stone)
  34. {
  35.     int sisyphus = stone;
  36.     do {
  37.         cout << sisyphus << endl;
  38.  
  39.         stone = sisyphus;
  40.         sisyphus = 0;
  41.  
  42.         int tmp = stone;
  43.         while (tmp > 0) {
  44.             sisyphus += (tmp % 2 == 0) ? 101 : 11;
  45.             tmp /= 10;
  46.         }
  47.     } while (sisyphus != stone);
  48. }
  49.  
  50. int main()
  51. {
  52.     const int __STONE__ = 43005798;
  53.     sisyphus1(__STONE__);
  54.     cout << endl;
  55.     sisyphus2(__STONE__);
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement