You really need to learn the difference between numbers and their (readable) representations!
More importantly, you need to learn to read and understand requirements:
- the input is a binary
string
- you need to (cyclic) rotate the digits of the binary
string input
- cyclic rotation means that you need to move the MSB of the current input into the LSB position
To put this into code, you first need to read a binary
string. So far you're not doing that - you're reading a decimal number:
long long a;
cin >> a;
Sure, your compiler doesn't complain, and you won't get a runtime error either, when trying to read "10101". But your program will not do what you think it does! If you could inspect the memory of a, you'd see that the number stored there is '2775' if viewed as hexadecimal, or '10011101110101' if viewed as binary.
Likewise, if you read 10 as input, cin interprets it as a decimal number, and internally stores it as 'A' (hexadecimal) or '1010' (binary).
You need to understand that '10'(decimal), 'A'(hexadecimal) and '1010'(binary) are all the same number, just
represented differently. And if you see one or the other representation, it doesn't mean the value is different, it means that the tool you use to view these values uses a different representation.
But, let's go back to the requirements: nothing in the requirement states that you have to actually store a number! All it says is that you should read a string, and manipulate that string. You
could convert that string into the number that it represents, but that would serve no purpose: you are not required to do any numerical processing! In fact, you don't really need to care that (or if) you're dealing with a number!
This means you can simply use a string. And to remind you what this string is for, you can choose a meaningful name for it:
std::string my_binary_number;
std::cin >> my_binary_number;
(I'm not a fan of
using namespace std;
, but that is not the point here)
As for rotating this string, it's not so hard to do. You can memorize the MSB:
char MSB = my_binary_number[0];
and then you can remove the first digit and append the MSB at the end.
Check the member functions of std::string to learn how you can achieve this:
string - C++ Reference[
^]
If you want to remove leading '0's, that is not a problem either. Nor is printing the current state of the string. But if you need further help, feel free to ask.