Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Parking_WhileGoto
- {
- public class Program
- {
- private static void Main()
- {
- int spotsTakenCount = 0;
- // parse first line
- string dimensions = Console.ReadLine();
- int rows = 0;
- int cols = 0;
- int index = dimensions.Length - 1;
- while (index >= 0)
- {
- char current;
- int powerIndex = -1;
- while ((current = dimensions[index--]) != ' ')
- {
- int multiplier = 1;
- int baseMultiplier = ++powerIndex;
- while (baseMultiplier-- > 0)
- {
- multiplier *= 10;
- }
- cols += (current - '0') * multiplier;
- }
- powerIndex = -1;
- while (index >= 0)
- {
- current = dimensions[index--];
- int multiplier = 1;
- int baseMultiplier = ++powerIndex;
- while (baseMultiplier-- > 0)
- {
- multiplier *= 10;
- }
- rows += (current - '0') * multiplier;
- }
- }
- int[] rowsTaken = new int[1000];
- int[] colsTaken = new int[1000];
- int c = 1000;
- while (--c >= 0)
- {
- rowsTaken[c] = -1;
- colsTaken[c] = -1;
- }
- // end parse first line
- string line;
- while ((line = Console.ReadLine()) != "stop")
- {
- // start take row input
- int startRow = 0;
- int targetRow = 0;
- int targetCol = 0;
- char current;
- int powerIndex = -1;
- index = line.Length - 1;
- while ((current = line[index--]) != ' ')
- {
- int multiplier = 1;
- int baseMultiplier = ++powerIndex;
- while (baseMultiplier-- > 0)
- {
- multiplier *= 10;
- }
- targetCol += (current - '0') * multiplier;
- }
- powerIndex = -1;
- while ((current = line[index--]) != ' ')
- {
- int multiplier = 1;
- int baseMultiplier = ++powerIndex;
- while (baseMultiplier-- > 0)
- {
- multiplier *= 10;
- }
- targetRow += (current - '0') * multiplier;
- }
- powerIndex = -1;
- while (index >= 0)
- {
- current = line[index--];
- int multiplier = 1;
- int baseMultiplier = ++powerIndex;
- while (baseMultiplier-- > 0)
- {
- multiplier *= 10;
- }
- startRow += (current - '0') * multiplier;
- }
- // end take row input
- bool isTaken = false;
- int rowIndex = 0;
- while (rowIndex < spotsTakenCount)
- {
- while (rowsTaken[rowIndex] == targetRow && colsTaken[rowIndex] == targetCol)
- {
- isTaken = true;
- goto SpotTaken;
- }
- rowIndex++;
- }
- SpotTaken:;
- while (isTaken)
- {
- int bestLength = 1000;
- int bestCol = 0;
- int colIndex = 1;
- while (colIndex < cols)
- {
- rowIndex = 0;
- while (rowIndex <= spotsTakenCount)
- {
- while (rowsTaken[rowIndex] == -1 && colsTaken[rowIndex] == -1)
- {
- int rowIndex2 = 0;
- while (rowIndex2 < spotsTakenCount)
- {
- while (rowsTaken[rowIndex2] == targetRow && colsTaken[rowIndex2] == colIndex)
- {
- goto SpotTaken2;
- }
- rowIndex2++;
- }
- int length = targetCol - colIndex;
- while (length < 0)
- {
- length *= -1;
- }
- while (length < bestLength && length != 0)
- {
- bestCol = colIndex;
- bestLength = length;
- break;
- }
- SpotTaken2:;
- break;
- }
- rowIndex++;
- }
- colIndex++;
- }
- while (bestCol == 0)
- {
- Console.WriteLine("Row " + targetRow + " full");
- goto EndWhile;
- }
- int rowLength = targetRow - startRow;
- while (rowLength < 0)
- {
- rowLength *= -1;
- }
- Console.WriteLine(rowLength + bestCol + 1);
- rowsTaken[spotsTakenCount] = targetRow;
- colsTaken[spotsTakenCount++] = bestCol;
- goto EndWhile;
- }
- int rowDist = targetRow - startRow;
- while (rowDist < 0)
- {
- rowDist *= -1;
- }
- Console.WriteLine(rowDist + targetCol + 1);
- rowsTaken[spotsTakenCount] = targetRow;
- colsTaken[spotsTakenCount++] = targetCol;
- EndWhile:;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement