Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class Solution {
- public static BufferedReader in;
- public static PrintWriter out;
- public static StringTokenizer st;
- public static void main(String[] args) throws IOException {
- in = new BufferedReader(new InputStreamReader(System.in));
- out = new PrintWriter(new OutputStreamWriter(System.out));
- new Solution().solve();
- out.close();
- }
- String line;
- public void solve() throws IOException {
- line = next();
- int n = line.length();
- Map<Integer, Integer> brackets = new HashMap<>();
- Stack<Integer> leftBrackets = new Stack<>();
- for (int i = 0; i < n; i++) {
- if (line.charAt(i) == '(') {
- leftBrackets.add(i);
- }
- if (line.charAt(i) == ')') {
- int start = leftBrackets.pop();
- brackets.put(start, i);
- }
- }
- System.out.println(process(1, n - 2));
- }
- String process(int l, int r) {
- StringBuilder number = new StringBuilder();
- while (Character.isDigit(line.charAt(l))) {
- number.append(line.charAt(l));
- ++l;
- }
- int n = Integer.parseInt(number.toString());
- StringBuilder res = new StringBuilder();
- String process = process(l, r);
- for (int i = 0; i < n; i++) {
- res.append(process);
- }
- return res.toString();
- }
- String next() throws IOException {
- while (st == null || !st.hasMoreTokens()) {
- st = new StringTokenizer(in.readLine());
- }
- return st.nextToken();
- }
- int nextInt() throws IOException {
- return Integer.parseInt(next());
- }
- long nextLong() throws IOException {
- return Long.parseLong(next());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement