Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.13 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Line_Moment
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int wrap = 20;
  14. List<string> words = new List<string>();
  15.  
  16.  
  17. words.Add("aaaaaaaa");
  18. words.Add("azzzzz");
  19. words.Add("ak");
  20. words.Add("fhgjhh"); words.Add("a");
  21. words.Add("afghjf");
  22. words.Add("a");
  23. words.Add("ak");
  24. words.Add("hh"); words.Add("a");
  25. words.Add("a");
  26. words.Add("a");
  27. words.Add("ak");
  28. words.Add("hh");
  29. words.Add("a");
  30. words.Add("ak");
  31. words.Add("hh");
  32. words.Add("a");
  33. words.Add("a");
  34. words.Add("a");
  35. words.Add("ak");
  36. words.Add("hh"); words.Add("a");
  37. words.Add("a");
  38. words.Add("a");
  39. words.Add("ak");
  40. words.Add("hh"); words.Add("a");
  41. words.Add("a");
  42. words.Add("a");
  43. words.Add("ak");
  44. words.Add("hh"); words.Add("a");
  45. words.Add("a");
  46. words.Add("a");
  47. words.Add("ak");
  48. words.Add("hh"); words.Add("a");
  49. words.Add("a");
  50. words.Add("a");
  51. words.Add("ak");
  52. words.Add("hh");
  53. words.Add("a");
  54.  
  55. words.Add("a");
  56.  
  57. words.Add("a");
  58.  
  59. words.Add("a");
  60.  
  61. words.Add("ha");
  62.  
  63.  
  64. words.Add("dnnkk");
  65.  
  66. words.Add("nn");
  67.  
  68. words.Add("a");
  69. words.Add("a");
  70. words.Add("a");
  71. words.Add("a");
  72. words.Add("hh");
  73.  
  74. words.Add("a");
  75.  
  76. words.Add("a");
  77.  
  78. words.Add("a");
  79.  
  80. words.Add("a");
  81.  
  82. words.Add("ha");
  83.  
  84.  
  85. words.Add("dnkk");
  86.  
  87. words.Add("nn");
  88.  
  89. int lineCount = 0;
  90. string formatedString = "";
  91. string line = "";
  92. line = "";
  93. formatedString = "";
  94. lineCount = 1;
  95. int space = 0;
  96. string finalLine;
  97. int bestScore;
  98. int count = 0;
  99. int currentHighest = 0;
  100. int backPos = 0;
  101. int column = 11;
  102. int maxSpaces = 0;
  103. int spaceCap=0;
  104. List<int> maxSpaceList = new List<int>();
  105. List<string> lineWords= new List<string>();
  106. for(int i=0;i<words.Count;i++)
  107. {
  108.  
  109.  
  110. if ((line + words[i]).Length <= wrap&& i + 1 != words.Count)
  111. {
  112.  
  113. line += words[i] + " ";
  114.  
  115. maxSpaceList.Add(0);
  116.  
  117. lineWords.Add(words[i]);
  118. spaceCap = wrap - (line.Trim()).Length;
  119. }
  120. else
  121. {
  122.  
  123.  
  124. finalLine = line.Trim();
  125. bestScore = LineMoment(column, finalLine);
  126. count =-1;
  127. currentHighest = 1;
  128. backPos = 0;
  129. space = wrap - (finalLine).Length;
  130.  
  131. if (maxSpaceList.Count > 0)
  132. {
  133. while (spaceCap >= maxSpaceList[0] && lineWords.Count != 1)
  134. {
  135. line = "";
  136. count++;
  137. if (count < maxSpaceList.Count)
  138. {
  139. if (currentHighest > maxSpaceList[count])
  140. {
  141. maxSpaceList[count] += 1;
  142. }
  143. }
  144. if (count >= maxSpaceList.Count)
  145. {
  146. if (maxSpaceList[backPos] == currentHighest)
  147. {
  148. backPos++;
  149.  
  150. }
  151. else
  152. {
  153.  
  154. maxSpaceList[backPos] += 1;
  155. }
  156. if (maxSpaceList[maxSpaceList.Count - 1] == currentHighest)
  157. {
  158. for (int x = 0; x < maxSpaceList.Count; x++)
  159. {
  160. maxSpaceList[x] = 0;
  161. }
  162. currentHighest++;
  163.  
  164.  
  165. backPos = 0;
  166. count = -1;
  167. }
  168. for (int x = backPos + 1; x < maxSpaceList.Count; x++)
  169. {
  170. maxSpaceList[x] = 0;
  171. }
  172.  
  173.  
  174. maxSpaceList[0] = currentHighest;
  175. }
  176.  
  177.  
  178. for (int j = 0; j < lineWords.Count; j++)
  179. {
  180. maxSpaces = maxSpaceList[j];
  181. line += lineWords[j];
  182. if (lineWords.Count != j + 1)
  183. {
  184. line += " ";
  185. }
  186. int k = 0;
  187.  
  188. if (lineWords.Count != j + 1)
  189. {
  190. while (maxSpaces > k)
  191. {
  192.  
  193. line += " ";
  194.  
  195.  
  196. k++;
  197.  
  198. }
  199.  
  200.  
  201. }
  202. space = wrap - (line).Length;
  203. if (bestScore > LineMoment(column, line) && lineWords.Count == j + 1)
  204. {
  205. if (space >= 0)
  206. {
  207. bestScore = LineMoment(column, line);
  208. finalLine = line;
  209. }
  210. }
  211.  
  212. }
  213. }
  214. }
  215.  
  216.  
  217. else
  218.  
  219. {
  220. finalLine = line;
  221. }
  222.  
  223.  
  224. if (finalLine != "")
  225. {
  226. lineWords = new List<string>();
  227. lineCount++;
  228. line = "";
  229. line += words[i] + " ";
  230. count = -1;
  231. currentHighest = 1;
  232. backPos = 0;
  233. lineWords.Add(words[i]);
  234.  
  235.  
  236. formatedString += finalLine + " " + bestScore.ToString() + "\n";
  237. finalLine = "";
  238.  
  239. maxSpaceList = new List<int>();
  240.  
  241. maxSpaceList.Add(0);
  242. spaceCap = wrap - (line.Trim()).Length;
  243. }
  244.  
  245.  
  246. }
  247.  
  248.  
  249. }
  250. Console.WriteLine(formatedString);
  251.  
  252.  
  253. Console.ReadLine();
  254. }
  255. static public int LineMoment(int column, string line)
  256. {
  257. int lineMoment = 0;
  258. for(int i=0; i < line.Length;i++)
  259. {
  260. if(line[i] != ' ')
  261. {
  262. lineMoment+=((i+1)- column) * ((int)line[i] % 32);
  263. }
  264. }
  265. return Math.Abs(lineMoment);
  266. }
  267. }
  268. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement