Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- namespace Advanced
- {
- class Program
- {
- static void Main(string[] args)
- {
- var input = Console.ReadLine();
- var stack = new Stack<int>();
- for (int i = 0; i < input.Length; i++)
- {
- if (input[i] == '(')
- {
- stack.Push(i);
- }
- if (input[i] == ')')
- {
- var startIndex = stack.Pop();
- string result = input.Substring(startIndex, i - startIndex + 1);
- Console.WriteLine(result);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment