Categories
Visual C# Телерик

Решение на задача – Moving Letters

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

namespace MovingLetters {
  class Program {
    static void Main() {
      string message = Console.ReadLine();
      List wordsList = new List(message.Split(' '));
      int lettersCount = wordsList.Sum(x => x.Length);
      int maxLetters = wordsList.Max(x => x.Length);
      StringBuilder sb = new StringBuilder();
      for (int i = 0; i < maxLetters; i++) {
        for (int j = 0; j < wordsList.Count; j++) {
          if (i < wordsList[j].Length) {
            sb.Append(wordsList[j][wordsList[j].Length - i - 1]);
          }
        }
      }
      int wordLettersCount = sb.Length;
      for (int i = 0; i < wordLettersCount; i++) {
        char letter = sb[i];
        sb.Remove(i, 1);
        int alphabetIndex = (letter < 97 ? letter - 64 : letter - 96);
        int wordIndex = i;
        while (alphabetIndex > 0) {
          wordIndex++;
          if (wordIndex == wordLettersCount) {
            wordIndex = 0;
          }
          alphabetIndex--;
        }
        sb.Insert(wordIndex, letter);
      }
      Console.WriteLine(sb.ToString());
    }
  }
}