Advertisement
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;
- class BitPaths
- {
- static void Main()
- {
- int N = int.Parse(Console.ReadLine());
- int[] numbers = new int[8];
- for (int i = 0; i < N; i++)
- {
- string currentInput = Console.ReadLine();
- int[] currentPath = Array.ConvertAll(currentInput.Split(','), x => int.Parse(x));
- int currentPosition = 3 - currentPath[0];
- for (int j = 0; j < 8; j++)
- {
- int currentBit = (numbers[j] >> currentPosition) & 1;
- if(currentBit == 1)
- {
- int mask = ~(1 << currentPosition);
- numbers[j] = numbers[j] & mask;
- }
- else
- {
- int mask = 1 << currentPosition;
- numbers[j] = numbers[j] | mask;
- }
- if (j == 7)
- {
- break;
- }
- currentPosition -= currentPath[j + 1];
- }
- }
- int sum = numbers.Sum();
- Console.WriteLine(Convert.ToString(sum, 2));
- Console.WriteLine(Convert.ToString(sum, 16).ToUpper());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement