Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace _5.FriendBits
- {
- using System;
- public class FriendBits
- {
- public static void Main(string[] args)
- {
- checked
- {
- uint num = uint.Parse(Console.ReadLine());
- uint friendBits = 0;
- uint aloneBits = 0;
- for (int i = 31; i >= 0; i--)
- {
- uint currentBitValue = (num >> i) & 1;
- uint leftBitValue = (num >> (i + 1)) & 1;
- uint rightBitValue = (num >> (i - 1)) & 1;
- if ((i < 31 && currentBitValue == leftBitValue) || (i > 0 && currentBitValue == rightBitValue))
- {
- friendBits = (friendBits << 1) | currentBitValue;
- }
- else
- {
- aloneBits = (aloneBits << 1) | currentBitValue;
- }
- }
- Console.WriteLine(friendBits);
- Console.WriteLine(aloneBits);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement