Deep_Dev

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AXjS1GXqZ8gDFATi 

 

SW Expert Academy

SW ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์—ญ๋Ÿ‰ ๊ฐ•ํ™”์— ๋„์›€์ด ๋˜๋Š” ๋‹ค์–‘ํ•œ ํ•™์Šต ์ปจํ…์ธ ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!

swexpertacademy.com

 

 

 


1. ์„œ๋กœ์˜ ๋‹ค๋ฅธ 2๊ฐœ๋ฌธ์ž

2. 2๋ฒˆ์”ฉ ๋“ฑ์žฅ

1+2 ==> ์ค‘๋ณต์„ ์ œ๊ฑฐํ–ˆ์„๋•Œ ์ด ๋ฌธ์ž๊ฐ€ 2๊ฐœ

Set์„ ์ด์šฉํ•˜๋ฉด ํŽธํ•˜๋‹ค.

 

 

import java.util.Scanner;
import java.util.HashSet;
 
class Solution{
    public static void main(String args[]) throws Exception{  
        Scanner kb = new Scanner(System.in);
        int T=kb.nextInt();
        String[] arr=new String[T];
        for(int test_case=0; test_case<T; test_case++) {
            String s = kb.next();
            HashSet<Character> set=new HashSet<>();
            for(char x:s.toCharArray()){
                set.add(x);
            }
            if(set.size()==2) arr[test_case]="Yes";
            else arr[test_case]="No";
        }
        for(int i=0; i<arr.length; i++) System.out.println("#"+(i+1)+" "+arr[i]);
    }
}