Deep_Lee
article thumbnail

 


์Šคํƒ์„ ์ด์šฉํ•ด์„œ ํ’€์–ด๋„ ๋˜๊ณ , ์ด์šฉํ•˜์ง€ ์•Š์•„๋„ ๋˜๋Š”๋ฐ 

์Šคํƒ์„ ์“ฐ๋ ค๊ณ  ์ด ๋ฌธ์ œ๋ฅผ ์ ‘๊ทผํ–ˆ๊ธฐ๋•Œ๋ฌธ์— ์Šคํƒ์„ ์‚ฌ์šฉํ•จ.

 

์ž…๋ ฅ๋ฐ›์€ ๋ฌธ์ž์—ด์„ ๊ณต๋ฐฑ์„ ๊ธฐ์ค€์œผ๋กœ ๋‚˜๋ˆˆ๋’ค์—, ๊ณต๋ฐฑ์œผ๋กœ ๋‚˜๋ˆˆ ๋ฌธ์ž์—ด์„ ๋ฉ์–ด๋ฆฌ์”ฉ stack์— ์ง‘์–ด๋„ฃ๊ณ 

๋ฐ˜๋Œ€๋กœ ๊บผ๋‚ด๋ฉด ๋œ๋‹ค.

 

๊ทผ๋ฐ Scanner๋ฅผ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ ,

์ž…๋ ฅ์„ ๋งจ ์ฒ˜์Œ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์˜ ๊ฐœ์ˆ˜์ธ T๋ฅผ intํ˜•์œผ๋กœ ๋ฐ›๊ณ , ๋ฌธ์ž์—ด์„ ๋ฐ›์œผ๋ ค๋‹ˆ ์ •์ƒ์ ์ธ ์ถœ๋ ฅ์ด ์•ˆ์ด๋ฃจ์–ด์ ธ์žˆ๊ธฐ์—

๊ฐœํ–‰์ฒ˜๋ฆฌ๋ฅผ ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค. 

 

 

 

import java.util.*;

class Main {
    public static void main(String args[]) throws Exception {
        Scanner kb = new Scanner(System.in);
        int T = kb.nextInt();
        kb.nextLine(); // ๊ฐœํ–‰์ฒ˜๋ฆฌ
        for (int t = 1; t <= T; t++) {
            String s = kb.nextLine();
            String[] arr = s.split(" ");
            Stack<String> stack = new Stack<>();
            for (int i = 0; i < arr.length; i++)
                stack.push(arr[i]);

            System.out.print("Case #" + t + ": ");
            while (!stack.isEmpty()) {
                System.out.print(stack.pop());
                System.out.print(" ");
                if (stack.isEmpty()) System.out.println();
            }
        }
    }
}