Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.IO;
- using System.Text;
- using System.Collections;
- using System.Collections.Generic;
- /**
- * Auto-generated code below aims at helping you parse
- * the standard input according to the problem statement.
- **/
- class Solution
- {
- static void Main(string[] args)
- {
- string[] inputs = Console.ReadLine().Split(' ');
- int W = int.Parse(inputs[0]);
- int H = int.Parse(inputs[1]);
- string[] header = null;
- string[] footer = null;
- string[] result = null;
- // column
- int k = 0; // resting column
- int headerIndex = 0; // starting column
- var lines = new string[H];
- // read all lines
- for (int i = 0; i < H; i++)
- {
- lines[i] = Console.ReadLine();
- Console.Error.WriteLine(lines[i]);
- }
- int letterColumns = lines[0].Split(' ', StringSplitOptions.RemoveEmptyEntries).Length;
- // for each column
- for (int j = 0; j < letterColumns; j++)
- {
- headerIndex = j; // starting column, this will be used later to retrive the header e.g: A, B, C
- k = j; // will be used alter to retrive the resting position. e.g: 1,2,3
- // headerIndex = 1;
- // k = 1;
- for (int i = 0; i < H; i++)
- {
- string line = lines[i];
- // read header
- if (i == 0)
- {
- header ??= line.Split(' ', StringSplitOptions.RemoveEmptyEntries);
- }
- // reader footer
- else if (i + 1 == H)
- {
- // read footer
- footer = line.Split(' ', StringSplitOptions.RemoveEmptyEntries);
- result ??= new String[header.Length];
- result[headerIndex] = header[headerIndex] + footer[k];
- }
- // read body
- else
- {
- // var parts = line.Split('|', StringSplitOptions.RemoveEmptyEntries);
- var parts = line.Split('|')
- /*
- if (k == 0 && parts[0] == "--")
- {
- k++;
- }*/
- if (k - 1 >= 0 && parts[k] == "--")
- {
- k--;
- }
- else if (k + 1 < letterColumns && parts[k + 1] == "--")
- {
- k++;
- }
- else if (k + 1 == letterColumns && parts[k] == "--")
- {
- k--;
- }
- }
- }
- }
- // Write an answer using Console.WriteLine()
- // To debug: Console.Error.WriteLine("Debug messages...");
- Console.WriteLine(string.Join(Environment.NewLine, result).Trim());
- }
- }
- // game: https://www.codingame.com/ide/puzzle/ghost-legs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement