๐ ์ฝ๋ฉํ
์คํธ/๋ฐฑ์ค & ํ๋ก๊ทธ๋๋จธ์ค
[SWEA][JAVA]D3 : ๋ฐ๋ฐ
deep_lee
2022. 11. 3. 17:23
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]);
}
}