-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathEC_CONB.cs
32 lines (28 loc) · 837 Bytes
/
EC_CONB.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
using System.Linq;
// https://www.spoj.com/problems/EC_CONB/ #ad-hoc #binary
// Reverses the binary representation of even numbers.
public static class EC_CONB
{
public static int Solve(int num)
{
if (num % 2 == 1)
return num;
string binaryRepresentation = Convert.ToString(num, toBase: 2);
string reversedbinaryRepresentation
= new string(binaryRepresentation.Reverse().ToArray());
return Convert.ToInt32(reversedbinaryRepresentation, fromBase: 2);
}
}
public static class Program
{
private static void Main()
{
int remainingTestCases = int.Parse(Console.ReadLine());
while (remainingTestCases-- > 0)
{
Console.WriteLine(
EC_CONB.Solve(int.Parse(Console.ReadLine())));
}
}
}