https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV14_DEKAJcCFAYD
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
문제가 참 예쁘다
번호가 비밀번호 1234네 ㅎ
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
//https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV14_DEKAJcCFAYD
public class Solution{
static int N;
static int Rkey;
static List<String> list;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
for (int tc = 1; tc <= 10; tc++) {
StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
list=new LinkedList<>();
String line=st.nextToken();
for (int i = 0; i < line.length(); i++) {
list.add(line.substring(i,i+1));
}
Rkey =1;
while(true){
if(Rkey >list.size()-1) break;
if (Rkey>0&&list.get(Rkey).equals(list.get(Rkey -1))) {
list.remove(Rkey);
list.remove(Rkey-1);
Rkey--;
}else{
Rkey++;
}
}
System.out.print("#"+tc+" ");
for(String s:list){
System.out.print(s);
}
System.out.println();
}
}
}
'노력만이 살길! > 알고리즘' 카테고리의 다른 글
[SWEA][JAVA] 13038 교환학생 (0) | 2022.03.01 |
---|---|
[SWEA][JAVA] 2005 파스칼의 삼각형 (0) | 2022.03.01 |
[SWEA][1220] 1220번 Magnetic (0) | 2022.03.01 |
[SWEA][JAVA] 2477 참외밭 (0) | 2022.03.01 |
[백준][JAVA] 2477 참외밭 (0) | 2022.02.27 |