Advertisement
yejolga

ol_5_04

Nov 4th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     ifstream cin("input.txt");
  10.  
  11.     int x;
  12.     cin>>x;
  13.  
  14.     string  a = "";
  15.     int tmp = x;
  16.     string stmp = "";
  17.     while (tmp != 0)
  18.     {
  19.         char c = tmp%10 + '0';
  20.         stmp = c + stmp;
  21.         tmp/=10;
  22.     }
  23.     a += stmp;
  24.     int i = 1;
  25.     while (x != 1)
  26.     {
  27.         a += ' ';
  28.         i++;
  29.         if (x%2 == 1)
  30.             x = 3*x+1;
  31.         else
  32.             x /=2;
  33.         int tmp = x;
  34.         string stmp = "";
  35.         while (tmp != 0)
  36.         {
  37.             char c = tmp%10 + '0';
  38.             stmp = c + stmp;
  39.             tmp/=10;
  40.         }
  41.         a += stmp;
  42.     }
  43.     cout<<i<<'\n';
  44.     cout<<a;
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement