Categories
Visual C# Телерик

Решение на задача – Magic Words

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MagicWords {
  class Program {
    static List wordsList = new List();
    static int wordsCount;
    static void Main() {
      wordsCount = int.Parse(Console.ReadLine());
      for (int i = 0; i < wordsCount; i++) {
        wordsList.Add(Console.ReadLine());
      }
      if (wordsCount > 1) {
        for (int oldIndex = 0; oldIndex < wordsCount; oldIndex++) {
          int wordLength = wordsList[oldIndex].Length;
          int newIndex = wordLength % (wordsCount + 1);
          ShiftElement(oldIndex, newIndex);
        }
        Print();
      } else {
        Console.WriteLine(wordsList[0]);
      }
    }
    static void Print() {
      int maxWordLength = wordsList.Max(w => w.Length);
      StringBuilder output = new StringBuilder();
      for (int letterIndex = 0; letterIndex < maxWordLength; letterIndex++) {
        for (int wordIndex = 0; wordIndex < wordsCount; wordIndex++) {
          if (letterIndex < wordsList[wordIndex].Length) {
            output.Append(wordsList[wordIndex].ToString()[letterIndex]);
          } else {
            continue;
          }
        }
      }
      Console.WriteLine(output.ToString());
    }
    static void ShiftElement(int oldIndex, int newIndex) {
      string word = wordsList[oldIndex];
      wordsList[oldIndex] = null;
      wordsList.Insert(newIndex, word);
      wordsList.Remove(null);
    }
  }
}