Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Apr 3rd, 2020 264 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.*;
  2. import java.util.*;
  3. public class Solution {
  4.     public static void main(String[] args) throws IOException{
  5.         Scanner scanner = new Scanner(System.in);
  6.         int T = scanner.nextInt();
  7.         for(int testcases = 1; testcases <= T; testcases++) {
  8.             String s = scanner.next();
  9.             String[] arr = s.split("");
  10.             ArrayList<String> answer = new ArrayList<>();
  11.             int open = 0;
  12.             for(int i = 0; i < arr.length; i++){
  13.                 int num = Integer.parseInt(arr[i]);
  14.                 int opening = 0;
  15.                 int closing = 0;
  16.                 if(num>open)opening+=num-open;
  17.                 if(num < open)closing+=open-num;
  18.                 open+=opening;
  19.                 open-=closing;
  20.                 for(int c = 0; c < opening; c++)answer.add("(");
  21.                 for(int c = 0; c < closing; c++)answer.add(")");
  22.                 answer.add(String.valueOf(num));
  23.             }
  24.             for(int i = 0; i < open; i++){
  25.                 answer.add(")");
  26.             }
  27.             System.out.print("Case #"+testcases+": ");
  28.             for(int i = 0; i < answer.size(); i++){
  29.                 System.out.print(answer.get(i));
  30.             }
  31.             System.out.println();
  32.         }
  33.     }
  34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top