Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication2
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- int number = 0;
- int changed = 0;
- List<int> counter = new List<int>();
- for (int i = 0; i < n; i++)
- {
- number = int.Parse(Console.ReadLine());
- string binary = Convert.ToString(number, 2);
- int positions = binary.Length;
- counter.Add(positions);
- }
- int l = int.Parse(Console.ReadLine());
- foreach (var item in counter)
- {
- for (int j = 0; j <= 2 * item - 2; j += 2)
- {
- int mask = 1 << j;
- int bitValue = (l & mask) >> j;
- if (bitValue == 0)
- {
- int maskForConversion = (1 << j);
- l = l | maskForConversion;
- changed++;
- }
- }
- }
- Console.WriteLine(l);
- Console.WriteLine(changed);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment