Advertisement
svetoslavhl

MagicWord

Dec 27th, 2013
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. using System;
  2.  
  3. using System.Collections.Generic;
  4.  
  5.  
  6. class Program
  7. {
  8.  
  9. static void Main(string[] args)
  10. {
  11.  
  12.  
  13.  
  14. int n = int.Parse(Console.ReadLine());
  15.  
  16. List<string> words = new List<string>();
  17.  
  18. for (int i = 0; i < n; i++) {
  19.  
  20. string enteredWord = Console.ReadLine();
  21. words.Add(enteredWord);
  22.  
  23. }
  24.  
  25. /* words.Add("nakov");
  26. words.Add("wrote");
  27. words.Add("this");
  28. words.Add("problem");*/
  29.  
  30. /*words.Remove("academy");
  31. words.Insert(0, "academy");
  32.  
  33. Console.WriteLine(words[0]);
  34. Console.WriteLine(words[1]);
  35. Console.WriteLine(words.Count);*/
  36.  
  37.  
  38. for (int i = 0; i < words.Count; i++) {
  39.  
  40. int pos = words[i].Length % (n + 1);
  41.  
  42. if (pos < words.Count) {
  43. string currentWord = words[i];
  44. words.Remove(words[i]);
  45. words.Insert(pos, currentWord);
  46.  
  47.  
  48.  
  49. }
  50.  
  51.  
  52. }
  53.  
  54.  
  55. //Izchisliavame dyljinata na naj dylgata duma
  56.  
  57.  
  58. int bestLenght = int.MinValue;
  59. string strToCheck = " ";
  60. for (int i = 0; i < words.Count; i++)
  61. {
  62. strToCheck = words[i];
  63.  
  64. if (strToCheck.Length > bestLenght)
  65. {
  66.  
  67. bestLenght = strToCheck.Length;
  68.  
  69.  
  70. }
  71.  
  72.  
  73.  
  74. }
  75.  
  76.  
  77. //Pravim vsichki taka
  78.  
  79. for (int i = 0; i < words.Count; i++)
  80. {
  81.  
  82. string currentWord = words[i];
  83.  
  84. for (int j = 0; j <= bestLenght; j++)
  85. {
  86.  
  87. if (currentWord.Length < j)
  88. {
  89.  
  90. currentWord += "#";
  91.  
  92. }
  93.  
  94.  
  95.  
  96.  
  97. }
  98.  
  99. words[i] = currentWord;
  100.  
  101.  
  102.  
  103. }
  104.  
  105.  
  106.  
  107. //Pochvame da syzdavame magicheskata duma
  108.  
  109. int f = 0;
  110. string wordToCheck = " ";
  111. string magicWord = "";
  112.  
  113. for (int i = 0; i < bestLenght; i++) {
  114.  
  115. for (int j = 0; j < words.Count; j++) {
  116. wordToCheck = words[j];
  117. if (wordToCheck[f] != '#') {
  118. magicWord += wordToCheck[f];
  119.  
  120. }
  121.  
  122.  
  123.  
  124. }
  125.  
  126. f++;
  127.  
  128.  
  129.  
  130. }
  131.  
  132.  
  133.  
  134.  
  135. Console.WriteLine(magicWord);
  136.  
  137.  
  138.  
  139. }
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement