-
[SWEA-1234] [S/W 문제해결 기본] 10일차 - 비밀번호 - Java공부/SWEA 2022. 6. 6. 13:21728x90
https://swexpertacademy.com/main/code/problem/problemDetail.do
코드
import java.util.*;public class swea1234 {public static void main(String args[]) throws Exception{Scanner sc = new Scanner(System.in);int T;T=10;for(int test_case = 1; test_case <= T; test_case++){Stack<Integer> stack=new Stack<>();int num=sc.nextInt();int []arr=new int[num];String str=sc.next();int count=0;for(int i=0;i<num;i++){arr[i]=str.charAt(i)-'0';}for(int i=0;i<num;i++){if(!stack.empty()){if(stack.peek()==arr[i]){count++;stack.pop();}else{stack.push(arr[i]);}}else{stack.push(arr[i]);}}int arr2[]=new int[num-count*2];for(int i=num-count*2-1;i>=0;i--){arr2[i]=stack.pop();}String answer="";for(int i=0;i<arr2.length;i++){answer+=arr2[i];}System.out.println("#"+test_case+" "+answer);}}}728x90반응형'공부 > SWEA' 카테고리의 다른 글
[SWEA-1961] 숫자 배열 회전 - Java (0) 2022.06.07 [SWEA-1984] 중간 평균값 구하기 - Java (0) 2022.06.06 [SWEA-1213] [S/W 문제해결 기본] 3일차 - String - Java (0) 2022.06.06 [SWEA-1217] [S/W 문제해결 기본] 4일차 - 거듭 제곱 - Java (0) 2022.06.05 [SWEA-1209] [S/W 문제해결 기본] 2일차 - Sum - Java (0) 2022.06.05