Notice
														
												
											
												
												
													Recent Posts
													
											
												
												
													Recent Comments
													
											
												
												
													Link
													
											
									| 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 | 
| 9 | 10 | 11 | 12 | 13 | 14 | 15 | 
| 16 | 17 | 18 | 19 | 20 | 21 | 22 | 
| 23 | 24 | 25 | 26 | 27 | 28 | 29 | 
| 30 | 
													Tags
													
											
												
												- 2961 java
 - django apache deploy error
 - django The requested operation has failed!
 - 1188 음식 평론가
 - 2661 좋은 수열
 - 공유기 원격 설정
 - django
 - windows 원격 연결 설정
 - django 웹 페이지
 - 2643 java
 - java di
 - django settings.py
 - The requested operation has failed!
 - windows apache wsgi 에러
 - django windows 배포 에러
 - 1188 java
 - 18233 러버덕
 - django 프로젝트 시작
 - 18233 비트마스킹
 - 14711 java
 - 2661 java
 - 2961 도영이가 만든 맛있는 음식
 - apache pythonpath
 - Problems occurred while performing provisioning operation
 - django httpd error
 - 18233 java
 - 원격 연결 포트 포워딩
 - 14711 타일 뒤집기
 - APPEND_SLASH = FALSE
 - 2643 색종이 올려 놓기
 
													Archives
													
											
									라이브러리는 도서관 아닌가요
백준 (BOJ) 12904 A와 B java 그리디 본문
https://www.acmicpc.net/problem/12904
12904번: A와 B
수빈이는 A와 B로만 이루어진 영어 단어가 존재한다는 사실에 놀랐다. 대표적인 예로 AB (Abdominal의 약자), BAA (양의 울음 소리), AA (용암의 종류), ABBA (스웨덴 팝 그룹)이 있다. 이런 사실에 놀란 수
www.acmicpc.net
꿀 문제
추가가 아닌 제거로 역접근하고,
각 단계마다 문자열을 하나씩 제거한다고 생각하면 쉽다. B의 경우에는 추가로 뒤집기하면 된다.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
    static String origin, target;
    static int index;
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        origin = br.readLine();
        target = br.readLine();
        index = target.length()-1;
        subtract();
    }
    //* 거꾸로 연산: 뒤에 A 빼기, 뒤에 B 빼고 뒤집기
    static void subtract(){
        while (target.length() != origin.length()){
            if(target.charAt(index) == 'A'){
                target = target.substring(0, index);
            }
            else{ // B다?
                target = target.substring(0, index);
                target = new StringBuilder(target).reverse().toString();
            }
            --index;
        }
        if(target.equals(origin)){
            System.out.print(1);
        }
        else{
            System.out.print(0);
        }
    }
}'알고리즘 문제' 카테고리의 다른 글
| 백준 (BOJ) 9084 동전 java dp (0) | 2022.07.05 | 
|---|---|
| 백준 (BOJ) 20058 마법사 상어와 파이어스톰 bfs, 구현 (0) | 2022.06.28 | 
| 백준 (BOJ) 18233 러버덕을 사랑하는 모임 java 백트래킹 (0) | 2022.06.24 | 
| 백준 (BOJ) 13019 A를 B로 java 그리디 (0) | 2022.06.11 | 
| 백준 (BOJ) 23351 물주기 java 그리디 (0) | 2022.06.10 | 
			  Comments