Advertisement
soxa

NeuronMapping

Apr 3rd, 2014
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class NeuronMapping
  5. {
  6.     static void Main()
  7.     {
  8.         List<uint> stackOfNumber = new List<uint>();
  9.         uint currentNumber = 0;
  10.  
  11.         while (uint.TryParse(Console.ReadLine(), out currentNumber))
  12.         {
  13.             stackOfNumber.Add(currentNumber);
  14.         }
  15.  
  16.         int rowSize = stackOfNumber.Count;
  17.         int colSize = 32;
  18.         int currentCountBits = 0;
  19.         string[,] matrix = new string[rowSize, colSize];
  20.  
  21.         for (int row = 0; row < rowSize; row++)
  22.         {
  23.             currentCountBits = 0;
  24.             currentNumber = stackOfNumber[row];
  25.             for (int col = 0; col < colSize; col++)
  26.             {
  27.                 matrix[row, colSize - 1 - col] = (currentNumber & 1).ToString();
  28.                 currentNumber >>= 1;
  29.             }
  30.         }
  31.  
  32.         string convertedBits = string.Empty;
  33.         bool canIWriteInMatrix = false;
  34.         bool oneInput = true;
  35.         int colWithOnes = 0;
  36.         for (int row = 0; row < rowSize; row++)
  37.         {
  38.             convertedBits = new string('0', 32);
  39.             canIWriteInMatrix = false;
  40.             oneInput = true;
  41.             for (int col = 0; col < colSize; col++)
  42.             {
  43.                 if (col + 1 < colSize && matrix[row, col] == "1" && matrix[row, col + 1] == "0" )
  44.                 {
  45.                     if (oneInput)
  46.                     {
  47.                         convertedBits = string.Empty;
  48.                         colWithOnes = col;
  49.                         oneInput = false;
  50.                     }
  51.  
  52.                     for (int i = 0; i < colSize ; i++)
  53.                     {
  54.                         if (canIWriteInMatrix == false && (i > colWithOnes) && (i+1 < colSize) && ((matrix[row, i + 1] == "0" && matrix[row, i] == "1") ||  (matrix[row, i] == "1" && matrix[row, i + 1] == "1")))
  55.                         {
  56.                             canIWriteInMatrix = true;
  57.                         }
  58.  
  59.                         if (i <= colWithOnes || canIWriteInMatrix)
  60.                         {
  61.                             convertedBits += "0";
  62.                         }
  63.                         else
  64.                         {
  65.                             convertedBits += "1";
  66.                         }
  67.                     }
  68.  
  69.                     if (canIWriteInMatrix)
  70.                     {
  71.                         for (int colWriter = 0; colWriter < colSize; colWriter++)
  72.                         {
  73.                             matrix[row, colWriter] = convertedBits[colWriter].ToString();
  74.                         }
  75.                     }
  76.                     else
  77.                     {
  78.                         convertedBits = new string('0', 32);
  79.                         for (int colWriter = 0; colWriter < colSize; colWriter++)
  80.                         {
  81.                             matrix[row, colWriter] = convertedBits[colWriter].ToString();
  82.                         }
  83.                     }
  84.                     break;
  85.                 }
  86.             }
  87.         }
  88.         uint sum = 0;
  89.         for (int row = 0; row < rowSize; row++)
  90.         {
  91.             for (int col = 0; col < colSize; col++)
  92.             {
  93.                 sum |= (uint.Parse(matrix[row,colSize - 1 - col]) & 1) << col;
  94.             }
  95.             Console.WriteLine(sum);
  96.             sum = 0;
  97.         }
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement