Milislavskii

MagicWords

Mar 17th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.67 KB | None | 0 0
  1. namespace Problem2
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Text;
  6.  
  7.     class MagicWords
  8.     {
  9.         static void Main()
  10.         {
  11.             int numberOfWords = int.Parse(Console.ReadLine());
  12.             string[] words = new string[numberOfWords];
  13.             var upgradeWords = new List<string>();
  14.             for (int i = 0; i < numberOfWords; i++)
  15.             {
  16.                 string currentWord = Console.ReadLine();
  17.                 words[i] = currentWord;
  18.                 upgradeWords.Add(currentWord);
  19.             }
  20.             for (int i = 0; i < upgradeWords.Count; i++)
  21.             {
  22.                 string currentWord = upgradeWords[i];
  23.                 int position = (upgradeWords[i].Length % (numberOfWords + 1));
  24.                 upgradeWords.Remove(upgradeWords[i]);
  25.                 upgradeWords.Insert(position,currentWord );
  26.             }
  27.  
  28.             int maxLenght = 0;
  29.             for (int i = 0; i < upgradeWords.Count; i++)
  30.             {
  31.                 int currentLenght = upgradeWords[i].Length;
  32.                 if (currentLenght > maxLenght)
  33.                 {
  34.                     maxLenght = currentLenght;
  35.                 }
  36.             }
  37.             StringBuilder result = new StringBuilder();
  38.             for (int i = 0; i < maxLenght; i++)
  39.             {
  40.                 for (int j = 0; j < upgradeWords.Count; j++)
  41.                 {
  42.                     if (upgradeWords[j].Length > i)
  43.                     {
  44.                         result.Append(upgradeWords[j][i]);
  45.                     }
  46.  
  47.                 }
  48.             }
  49.  
  50.             Console.WriteLine(result.ToString());
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment