Advertisement
ivan_yosifov

Genome_Decoder

Dec 25th, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. class Program
  5. {
  6.     static void Main()
  7.     {        
  8.         string input = Console.ReadLine();
  9.         string[] numbers = input.Split();
  10.         int N = int.Parse(numbers[0].ToString());
  11.         int M = int.Parse(numbers[1].ToString());
  12.         input = Console.ReadLine();
  13.  
  14.         StringBuilder sb = new StringBuilder();
  15.         string howMany = "0";
  16.  
  17.         for (int i = 0; i < input.Length; i++)
  18.         {
  19.             char ch = input[i];
  20.             if (ch == 'A' || ch == 'C' || ch == 'G' || ch == 'T')
  21.             {
  22.                 if (howMany == "0") howMany = "1";
  23.                 sb.Append(ch, int.Parse(howMany));
  24.                 howMany = "0";
  25.                 continue;
  26.             }
  27.             howMany += ch.ToString();
  28.  
  29.         }
  30.  
  31.         int rowCount = sb.Length / N;
  32.         if (sb.Length % N != 0) rowCount++;
  33.         int padCount = rowCount.ToString().Length;
  34.         int index = 0;
  35.  
  36.         for(int i = 0; i < rowCount; i++)
  37.         {
  38.             StringBuilder line = new StringBuilder();
  39.             line.Append((i+1).ToString().PadLeft(padCount, ' '));
  40.             for (int j = 0; j < N; j++)
  41.             {
  42.                 if (j % M == 0)
  43.                 {
  44.                     line.Append(" " + sb[index]);
  45.                 }
  46.                 else
  47.                 {
  48.                     line.Append(sb[index]);
  49.                 }
  50.                 index++;
  51.                 if (index > sb.Length - 1) break;
  52.             }
  53.             Console.WriteLine(line);
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement