๐Ÿ“Œ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ค€๋น„ :: ๋ฐฑ์ค€_14713:: ์Šคํƒ&ํ - ์•ต๋ฌด์ƒˆ๐Ÿ‘€

Dev-Oยท2022๋…„ 2์›” 17์ผ
0

CodingTest

๋ชฉ๋ก ๋ณด๊ธฐ
15/18

๋ฌธ์ œ

ํ’€์ด

ํ•œ ์•ต๋ฌด์ƒˆ๊ฐ€ ๋งํ•˜๋Š” ๊ฒƒ์„ ํ•˜๋‚˜์˜ ํ์— ๋„ฃ์–ด์ค๋‹ˆ๋‹ค.
๊ทธ๋ฆฌ๊ณ  ์•ต๋ฌด์ƒˆ ํ๋ฅผ ๋ฆฌ์ŠคํŠธ์— ๋‹ด์•„์ค๋‹ˆ๋‹ค.
๊ทธ๋ฆฌ๊ณ  cestream์ด ๋ฐ›์•„์ ์€ ๋ฌธ์žฅ์„ ๊ณต๋ฐฑ ๋‹จ์œ„๋กœ ๋ฐ›์•„์™€์„œ ๋ฆฌ์ŠคํŠธ์— ์žˆ๋Š” ํ์™€ ํ™•์ธ์ž‘์—…์„ ํ•ฉ๋‹ˆ๋‹ค.

ํ™•์ธ 1) cestream๊ณผ ๋ฆฌ์ŠคํŠธ์— ์žˆ๋Š” ํ๋ฅผ ํ™•์ธ
ํ™•์ธ 2) cestream์€ ์ง€์›Œ์กŒ๋Š”๋ฐ ์•ต๋ฌด์ƒˆ ํ๊ฐ€ ๋‚จ์€๊ฒฝ์šฐ

ํ™•์ธ 2๋•Œ๋ฌธ์— ์‹œ๊ฐ„์„ ์ข€ ๋งŽ์ด ํ—ˆ๋น„ ํ–ˆ๋‹ค.

์ฝ”๋“œ

import jdk.nashorn.internal.ir.WhileNode;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;


public class Bj14713_Parrot {

    public static void main(String[] args) throws IOException {

        ArrayList<Queue<String>>  Plist = new ArrayList<>();
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());


        for(int i = 0; i < n ; i++){
            Queue<String> q = new LinkedList<>();
            String string = br.readLine();
            String[] st = string.split(" ");
            for (int k = 0 ; k < st.length ; k++) {
                q.offer(st[k]);
            }
            Plist.add(q);
        }

        String question = br.readLine();

        String[] qArr = question.split(" ");

        boolean f = true;
        for (int i = 0; i < qArr.length; i++) {
            if(!f) {
                break;
            }
            for(int k = 0; k < Plist.size() ; k++) {
                f = false;
                if(!(Plist.get(k).isEmpty()) && Plist.get(k).peek().equals(qArr[i])){//0,
                    Plist.get(k).poll();
                    f = true;
                    break;
                }
            }
        }
        while (!Plist.isEmpty()) {
            if(Plist.get(0).isEmpty()) {
                Plist.remove(0);
            }else{
                break;
            }
        }
        if(f && Plist.isEmpty()) {
            System.out.println("Possible");
        }else {
            System.out.println("Impossible");
        }


    }
}
profile
Being Outstanding needs Understanding๐Ÿš€

0๊ฐœ์˜ ๋Œ“๊ธ€