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.Text.RegularExpressions;
- namespace _01.GenomeDecoder
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] dimensions = Console.ReadLine().Split(' ');
- int line = int.Parse(dimensions[0]);
- int space = int.Parse(dimensions[1]);
- string genome = Console.ReadLine();
- string pattern = @"(\d*)(\w)";
- List<int> count = new List<int>();
- List<string> letter = new List<string>();
- bool finished = false;
- foreach (Match match in Regex.Matches(genome,pattern))
- {
- int countLetter=0;
- if (!int.TryParse(match.Groups[1].Value, out countLetter))
- {
- countLetter = 1;
- }
- string currentLetter = match.Groups[2].Value;
- count.Add(countLetter);
- letter.Add(currentLetter);
- }
- int printedLetter = 0;
- int lineCount = 1;
- int totalSum = count.Sum();
- int totalLines = totalSum / line;
- if (totalSum%line != 0)
- {
- totalLines++;
- }
- int padding = totalLines.ToString().Length;
- string realPadding = "{0," + padding + "} ";
- StringBuilder output = new StringBuilder();
- string format = String.Format(realPadding, lineCount);
- output.Append(format);
- realPadding = "\n" + realPadding;
- lineCount++;
- int length = count.Count;
- for (int i = 0; i < length; i++)
- {
- int letterLength = count[i];
- for (int j = 0; j < letterLength; j++)
- {
- output.Append(letter[i]);
- printedLetter++;
- if (i == count.Count - 1 && j == count[i] - 1)
- {
- finished = true;
- }
- if(printedLetter%line == 0 && finished == false)
- {
- output.Append(String.Format(realPadding, lineCount));
- lineCount++;
- printedLetter = 0;
- }
- else if (printedLetter % space == 0 && finished == false)
- {
- output.Append(' ');
- }
- }
- }
- Console.WriteLine(output);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement