Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text.RegularExpressions;
- using System.Text;
- class Brackets
- {
- static void Main()
- {
- StringBuilder text = new StringBuilder();
- int n = int.Parse(Console.ReadLine());
- string pad = Console.ReadLine();
- while (n > 0)
- {
- text.Append(Console.ReadLine().Trim());
- text.Append("\r\n");
- n--;
- }
- string line = text.ToString().Replace("{", "`{`").Replace("}", "`}`").Trim();
- string[] lines = line.Split(new string[] { "\r\n", "`" }, StringSplitOptions.RemoveEmptyEntries);
- text.Clear();
- int counter = 0;
- for (int i = 0; i < lines.Length; i++)
- {
- lines[i] = Regex.Replace(lines[i], @"(\s+)", " ");
- lines[i] = lines[i].Trim();
- if (lines[i]=="{")
- {
- for (int j = 0; j < counter; j++)
- {
- lines[i] = lines[i].Insert(0, pad);
- }
- counter++;
- text.Append(lines[i]);
- text.Append("\r\n");
- continue;
- }
- if (lines[i]=="}")
- {
- for (int j = 0; j < counter- 1; j++)
- {
- lines[i] = lines[i].Insert(0, pad);
- }
- counter--;
- text.Append(lines[i]);
- text.Append("\r\n");
- continue;
- }
- else if (lines[i] != String.Empty)
- {
- for (int j = 0; j < counter; j++)
- {
- lines[i] = lines[i].Insert(0, pad);
- }
- text.Append(lines[i]);
- text.Append("\r\n");
- }
- }
- string babab = text.ToString();
- Console.WriteLine(babab);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement