https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AXjS1GXqZ8gDFATi
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]);
}
}
'๐ ์ฝ๋ฉํ ์คํธ > ๋ฐฑ์ค & ํ๋ก๊ทธ๋๋จธ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค][JAVA]Level 0 : ์ง์ฌ๊ฐํ ๋์ด ๊ตฌํ๊ธฐ (0) | 2022.11.04 |
---|---|
[SWEA][JAVA]D3 : ์ก์ด (0) | 2022.11.03 |
[SWEA][JAVA]D2 : ์ค์ ํ๊ท ๊ฐ ๊ตฌํ๊ธฐ (0) | 2022.11.03 |
[ํ๋ก๊ทธ๋๋จธ์ค][JAVA]Level 1 : ์ฝ๋ผ ๋ฌธ์ (0) | 2022.11.03 |
[ํ๋ก๊ทธ๋๋จธ์ค][JAVA]Level 0 : ์ผ๊ฐํ์ ์์ฑ์กฐ๊ฑด(2) (0) | 2022.11.03 |