Advertisement
Guest User

Untitled

a guest
Jun 29th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <conio.h>
  3. #include <iostream>
  4. #include <string>
  5. using namespace std;
  6. void main()
  7. {
  8.     int N, d, B[20], t = 0, temp, c;
  9.     char *max;
  10.     cin >> N;
  11.     string result;
  12.     do
  13.     {
  14.         result = (char)('0' + (N % 2)) + result;
  15.         N = N / 2;
  16.     } while (N > 0);
  17.  
  18.     char* str = new char[result.size() + 1];
  19.     strcpy(str, result.c_str());
  20.     for (int i = 0; i < result.size() + 1; i++)
  21.         cout << str[i];
  22.  
  23.  
  24.     cout << endl<<endl;
  25.     max=str;
  26.     for (int j=0;j<result.size();j++)
  27.     {
  28.        
  29.     temp = str[result.size() - 1];
  30.     for (int i = result.size()-1; i >= 0; i--)
  31.     {
  32.         str[i] = str[i - 1];
  33.     }
  34.     str[0] = temp;
  35.     if (strcmp(str,max)>0)
  36.         max=str;
  37.         cout<<max;
  38.     }
  39.     for (int i = 0; i < result.size() + 1; i++)
  40.         cout << max[i];
  41.  
  42.     _getch();
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement