Advertisement
enevlogiev

WhileGotoBullshit

Mar 1st, 2016
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.47 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Parking_WhileGoto
  4. {
  5.     public class Program
  6.     {
  7.         private static void Main()
  8.         {
  9.             int spotsTakenCount = 0;
  10.             // parse first line
  11.             string dimensions = Console.ReadLine();
  12.             int rows = 0;
  13.             int cols = 0;
  14.             int index = dimensions.Length - 1;
  15.             while (index >= 0)
  16.             {
  17.                 char current;
  18.                 int powerIndex = -1;
  19.                 while ((current = dimensions[index--]) != ' ')
  20.                 {
  21.                     int multiplier = 1;
  22.                     int baseMultiplier = ++powerIndex;
  23.                     while (baseMultiplier-- > 0)
  24.                     {
  25.                         multiplier *= 10;
  26.                     }
  27.  
  28.                     cols += (current - '0') * multiplier;
  29.                 }
  30.  
  31.                 powerIndex = -1;
  32.                 while (index >= 0)
  33.                 {
  34.                     current = dimensions[index--];
  35.                     int multiplier = 1;
  36.                     int baseMultiplier = ++powerIndex;
  37.                     while (baseMultiplier-- > 0)
  38.                     {
  39.                         multiplier *= 10;
  40.                     }
  41.  
  42.                     rows += (current - '0') * multiplier;
  43.                 }
  44.             }
  45.  
  46.             int[] rowsTaken = new int[1000];
  47.             int[] colsTaken = new int[1000];
  48.             int c = 1000;
  49.             while (--c >= 0)
  50.             {
  51.                 rowsTaken[c] = -1;
  52.                 colsTaken[c] = -1;
  53.             }
  54.             // end parse first line
  55.  
  56.             string line;
  57.             while ((line = Console.ReadLine()) != "stop")
  58.             {
  59.                 // start take row input
  60.                 int startRow = 0;
  61.                 int targetRow = 0;
  62.                 int targetCol = 0;
  63.                 char current;
  64.                 int powerIndex = -1;
  65.                 index = line.Length - 1;
  66.                 while ((current = line[index--]) != ' ')
  67.                 {
  68.                     int multiplier = 1;
  69.                     int baseMultiplier = ++powerIndex;
  70.                     while (baseMultiplier-- > 0)
  71.                     {
  72.                         multiplier *= 10;
  73.                     }
  74.  
  75.                     targetCol += (current - '0') * multiplier;
  76.                 }
  77.  
  78.                 powerIndex = -1;
  79.                 while ((current = line[index--]) != ' ')
  80.                 {
  81.                     int multiplier = 1;
  82.                     int baseMultiplier = ++powerIndex;
  83.                     while (baseMultiplier-- > 0)
  84.                     {
  85.                         multiplier *= 10;
  86.                     }
  87.  
  88.                     targetRow += (current - '0') * multiplier;
  89.                 }
  90.  
  91.                 powerIndex = -1;
  92.                 while (index >= 0)
  93.                 {
  94.                     current = line[index--];
  95.                     int multiplier = 1;
  96.                     int baseMultiplier = ++powerIndex;
  97.                     while (baseMultiplier-- > 0)
  98.                     {
  99.                         multiplier *= 10;
  100.                     }
  101.  
  102.                     startRow += (current - '0') * multiplier;
  103.                 }
  104.                 // end take row input
  105.  
  106.                 bool isTaken = false;
  107.                 int rowIndex = 0;
  108.                 while (rowIndex < spotsTakenCount)
  109.                 {
  110.                     while (rowsTaken[rowIndex] == targetRow && colsTaken[rowIndex] == targetCol)
  111.                     {
  112.                         isTaken = true;
  113.                         goto SpotTaken;
  114.                     }
  115.                     rowIndex++;
  116.                 }
  117.  
  118.                 SpotTaken:;
  119.                 while (isTaken)
  120.                 {
  121.                     int bestLength = 1000;
  122.                     int bestCol = 0;
  123.                     int colIndex = 1;
  124.                     while (colIndex < cols)
  125.                     {
  126.                         rowIndex = 0;
  127.                         while (rowIndex <= spotsTakenCount)
  128.                         {
  129.                             while (rowsTaken[rowIndex] == -1 && colsTaken[rowIndex] == -1)
  130.                             {
  131.                                 int rowIndex2 = 0;
  132.                                 while (rowIndex2 < spotsTakenCount)
  133.                                 {
  134.                                     while (rowsTaken[rowIndex2] == targetRow && colsTaken[rowIndex2] == colIndex)
  135.                                     {
  136.                                         goto SpotTaken2;
  137.                                     }
  138.                                     rowIndex2++;
  139.                                 }
  140.                                 int length = targetCol - colIndex;
  141.                                 while (length < 0)
  142.                                 {
  143.                                     length *= -1;
  144.                                 }
  145.                                 while (length < bestLength && length != 0)
  146.                                 {
  147.                                     bestCol = colIndex;
  148.                                     bestLength = length;
  149.                                     break;
  150.                                 }
  151.                                 SpotTaken2:;
  152.                                 break;
  153.                             }
  154.                             rowIndex++;
  155.                         }
  156.                         colIndex++;
  157.                     }
  158.  
  159.                     while (bestCol == 0)
  160.                     {
  161.                         Console.WriteLine("Row " + targetRow + " full");
  162.                         goto EndWhile;
  163.                     }
  164.  
  165.                     int rowLength = targetRow - startRow;
  166.                     while (rowLength < 0)
  167.                     {
  168.                         rowLength *= -1;
  169.                     }
  170.  
  171.                     Console.WriteLine(rowLength + bestCol + 1);
  172.  
  173.                     rowsTaken[spotsTakenCount] = targetRow;
  174.                     colsTaken[spotsTakenCount++] = bestCol;
  175.  
  176.                     goto EndWhile;
  177.                 }
  178.  
  179.                 int rowDist = targetRow - startRow;
  180.                 while (rowDist < 0)
  181.                 {
  182.                     rowDist *= -1;
  183.                 }
  184.                 Console.WriteLine(rowDist + targetCol + 1);
  185.                
  186.                 rowsTaken[spotsTakenCount] = targetRow;
  187.                 colsTaken[spotsTakenCount++] = targetCol;
  188.  
  189.                 EndWhile:;
  190.             }
  191.         }
  192.     }
  193. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement