staafl

Untitled

Jul 14th, 2013
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Text.RegularExpressions;
  4.  
  5. class CSharpBrackets
  6. {
  7. static void Main()
  8. {
  9. int n = int.Parse(Console.ReadLine());
  10. string pad = Console.ReadLine();
  11. StringBuilder sb = new StringBuilder();
  12. for (int i = 0; i < n; i++)
  13. {
  14. sb.Append(Console.ReadLine().Trim());
  15. sb.Append("\0");
  16. }
  17. string line = sb.ToString().Replace("{", "\0{\0").Replace("}", "\0}\0").Trim();
  18. line = Regex.Replace(line, @"\s+", " ");
  19. string[] lines = line.Split(new string[] { "\r\n", "\0" }, StringSplitOptions.RemoveEmptyEntries);
  20. sb.Clear();
  21. int count = 0;
  22. for (int i = 0; i < lines.Length; i++)
  23. {
  24. string textLine = lines[i].Trim();
  25. if (textLine == "")
  26. continue;
  27. if (textLine == "}")
  28. count--;
  29. for (int ii = 0; ii < count; ii++)
  30. {
  31. sb.Append(pad);
  32. }
  33. sb.Append(textLine);
  34. foreach (char ch in textLine)
  35. {
  36. if (ch == '{')
  37. count++;
  38. }
  39. sb.AppendLine();
  40. }
  41. string result = sb.ToString();
  42. Console.Write(result);
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment