Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Line_Moment
- {
- class Program
- {
- static void Main(string[] args)
- {
- int wrap = 20;
- List<string> words = new List<string>();
- words.Add("aaaaaaaa");
- words.Add("azzzzz");
- words.Add("ak");
- words.Add("fhgjhh"); words.Add("a");
- words.Add("afghjf");
- words.Add("a");
- words.Add("ak");
- words.Add("hh"); words.Add("a");
- words.Add("a");
- words.Add("a");
- words.Add("ak");
- words.Add("hh");
- words.Add("a");
- words.Add("ak");
- words.Add("hh");
- words.Add("a");
- words.Add("a");
- words.Add("a");
- words.Add("ak");
- words.Add("hh"); words.Add("a");
- words.Add("a");
- words.Add("a");
- words.Add("ak");
- words.Add("hh"); words.Add("a");
- words.Add("a");
- words.Add("a");
- words.Add("ak");
- words.Add("hh"); words.Add("a");
- words.Add("a");
- words.Add("a");
- words.Add("ak");
- words.Add("hh"); words.Add("a");
- words.Add("a");
- words.Add("a");
- words.Add("ak");
- words.Add("hh");
- words.Add("a");
- words.Add("a");
- words.Add("a");
- words.Add("a");
- words.Add("ha");
- words.Add("dnnkk");
- words.Add("nn");
- words.Add("a");
- words.Add("a");
- words.Add("a");
- words.Add("a");
- words.Add("hh");
- words.Add("a");
- words.Add("a");
- words.Add("a");
- words.Add("a");
- words.Add("ha");
- words.Add("dnkk");
- words.Add("nn");
- int lineCount = 0;
- string formatedString = "";
- string line = "";
- line = "";
- formatedString = "";
- lineCount = 1;
- int space = 0;
- string finalLine;
- int bestScore;
- int count = 0;
- int currentHighest = 0;
- int backPos = 0;
- int column = 11;
- int maxSpaces = 0;
- int spaceCap=0;
- List<int> maxSpaceList = new List<int>();
- List<string> lineWords= new List<string>();
- for(int i=0;i<words.Count;i++)
- {
- if ((line + words[i]).Length <= wrap&& i + 1 != words.Count)
- {
- line += words[i] + " ";
- maxSpaceList.Add(0);
- lineWords.Add(words[i]);
- spaceCap = wrap - (line.Trim()).Length;
- }
- else
- {
- finalLine = line.Trim();
- bestScore = LineMoment(column, finalLine);
- count =-1;
- currentHighest = 1;
- backPos = 0;
- space = wrap - (finalLine).Length;
- if (maxSpaceList.Count > 0)
- {
- while (spaceCap >= maxSpaceList[0] && lineWords.Count != 1)
- {
- line = "";
- count++;
- if (count < maxSpaceList.Count)
- {
- if (currentHighest > maxSpaceList[count])
- {
- maxSpaceList[count] += 1;
- }
- }
- if (count >= maxSpaceList.Count)
- {
- if (maxSpaceList[backPos] == currentHighest)
- {
- backPos++;
- }
- else
- {
- maxSpaceList[backPos] += 1;
- }
- if (maxSpaceList[maxSpaceList.Count - 1] == currentHighest)
- {
- for (int x = 0; x < maxSpaceList.Count; x++)
- {
- maxSpaceList[x] = 0;
- }
- currentHighest++;
- backPos = 0;
- count = -1;
- }
- for (int x = backPos + 1; x < maxSpaceList.Count; x++)
- {
- maxSpaceList[x] = 0;
- }
- maxSpaceList[0] = currentHighest;
- }
- for (int j = 0; j < lineWords.Count; j++)
- {
- maxSpaces = maxSpaceList[j];
- line += lineWords[j];
- if (lineWords.Count != j + 1)
- {
- line += " ";
- }
- int k = 0;
- if (lineWords.Count != j + 1)
- {
- while (maxSpaces > k)
- {
- line += " ";
- k++;
- }
- }
- space = wrap - (line).Length;
- if (bestScore > LineMoment(column, line) && lineWords.Count == j + 1)
- {
- if (space >= 0)
- {
- bestScore = LineMoment(column, line);
- finalLine = line;
- }
- }
- }
- }
- }
- else
- {
- finalLine = line;
- }
- if (finalLine != "")
- {
- lineWords = new List<string>();
- lineCount++;
- line = "";
- line += words[i] + " ";
- count = -1;
- currentHighest = 1;
- backPos = 0;
- lineWords.Add(words[i]);
- formatedString += finalLine + " " + bestScore.ToString() + "\n";
- finalLine = "";
- maxSpaceList = new List<int>();
- maxSpaceList.Add(0);
- spaceCap = wrap - (line.Trim()).Length;
- }
- }
- }
- Console.WriteLine(formatedString);
- Console.ReadLine();
- }
- static public int LineMoment(int column, string line)
- {
- int lineMoment = 0;
- for(int i=0; i < line.Length;i++)
- {
- if(line[i] != ' ')
- {
- lineMoment+=((i+1)- column) * ((int)line[i] % 32);
- }
- }
- return Math.Abs(lineMoment);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement