Advertisement
ivandrofly

Ghost Legs - coding games

Mar 8th, 2021 (edited)
857
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.01 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.IO;
  4. using System.Text;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7.  
  8. /**
  9.  * Auto-generated code below aims at helping you parse
  10.  * the standard input according to the problem statement.
  11.  **/
  12. class Solution
  13. {
  14.     static void Main(string[] args)
  15.     {
  16.         string[] inputs = Console.ReadLine().Split(' ');
  17.         int W = int.Parse(inputs[0]);
  18.         int H = int.Parse(inputs[1]);
  19.  
  20.         string[] header = null;
  21.         string[] footer = null;
  22.         string[] result = null;
  23.         // column
  24.         int k = 0; // resting column
  25.         int headerIndex = 0; // starting column
  26.  
  27.         var lines = new string[H];
  28.  
  29.         // read all lines
  30.         for (int i = 0; i < H; i++)
  31.         {
  32.             lines[i] = Console.ReadLine();
  33.             Console.Error.WriteLine(lines[i]);
  34.         }
  35.  
  36.         int letterColumns = lines[0].Split(' ', StringSplitOptions.RemoveEmptyEntries).Length;
  37.  
  38.         // for each column
  39.         for (int j = 0; j < letterColumns; j++)
  40.         {
  41.             headerIndex = j; // starting column, this will be used later to retrive the header e.g: A, B, C
  42.             k = j; // will be used alter to retrive the resting position. e.g: 1,2,3
  43.  
  44.             // headerIndex = 1;
  45.             // k = 1;
  46.             for (int i = 0; i < H; i++)
  47.             {
  48.                 string line = lines[i];
  49.  
  50.                 // read header
  51.                 if (i == 0)
  52.                 {
  53.                     header ??= line.Split(' ', StringSplitOptions.RemoveEmptyEntries);
  54.                 }
  55.                 // reader footer
  56.                 else if (i + 1 == H)
  57.                 {
  58.                     // read footer
  59.                     footer = line.Split(' ', StringSplitOptions.RemoveEmptyEntries);
  60.                     result ??= new String[header.Length];
  61.                     result[headerIndex] = header[headerIndex] + footer[k];
  62.                 }
  63.                 // read body
  64.                 else
  65.                 {
  66.                     // var parts = line.Split('|', StringSplitOptions.RemoveEmptyEntries);
  67.                     var parts = line.Split('|')
  68.  
  69. /*
  70.                     if (k == 0 && parts[0] == "--")
  71.                     {
  72.                         k++;
  73.                     }*/
  74.                     if (k - 1 >= 0 && parts[k] == "--")
  75.                     {
  76.                         k--;
  77.                     }
  78.                     else if (k + 1 < letterColumns && parts[k + 1] == "--")
  79.                     {
  80.                         k++;
  81.                     }
  82.                     else if (k + 1 == letterColumns && parts[k] == "--")
  83.                     {
  84.                         k--;
  85.                     }
  86.                 }
  87.             }
  88.         }
  89.  
  90.  
  91.         // Write an answer using Console.WriteLine()
  92.         // To debug: Console.Error.WriteLine("Debug messages...");
  93.         Console.WriteLine(string.Join(Environment.NewLine, result).Trim());
  94.     }
  95. }
  96.  
  97. // game: https://www.codingame.com/ide/puzzle/ghost-legs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement