-
[JAVA 백준 문제풀이] 얼렁뚱땅 20546 기적의 매매법 풀이얼렁뚱땅 JAVA 문제풀이 2023. 2. 27. 14:24
https://www.acmicpc.net/problem/20546
20546번: 🐜 기적의 매매법 🐜
1월 14일 기준 준현이의 자산이 더 크다면 "BNP"를, 성민이의 자산이 더 크다면 "TIMING"을 출력한다. 둘의 자산이 같다면 "SAMESAME"을 출력한다. 모든 결과 따옴표를 제외하고 출력한다.
www.acmicpc.net
어려운 걸 푼다 보다는 문법을 빨리 외우기 위해 풀어보고자 하였다.
그래서 비교적 난이도는 매우 낮지만
하나씩 풀면서 얼른 자바랑 친해져야겠다 🥲
// Main으로 바꿔서 제출해야 됨 import java.util.*; import java.io.*; public class 기적의매매법_20546 { public static void main(String[] args) throws IOException { // TODO Auto-generated method stub BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int money_jun = Integer.valueOf(Integer.parseInt(br.readLine())); int money_sung = money_jun; int joo_jun = 0; int joo_sung = 0; // 2번 상승 or 하락 판별 시 사야됨 성민이 int sung_count = 0; // 상승 1, 하락 2, 일단 몰라 0 int sung_sign = 0; String temp = br.readLine(); StringTokenizer st = new StringTokenizer(temp); int yesterday = 0; int today = 0; int all_token = st.countTokens(); for(int i = 0;i<all_token;i++) { today = Integer.parseInt(st.nextToken()); if (i != 0) { if (yesterday < today) { if (sung_sign <= 1) { sung_count += 1; sung_sign = 1; } else { sung_count = 0; sung_sign = 1; } } else { if (sung_sign == 0 || sung_sign == 2) { sung_count += 1; sung_sign = 2; } else { sung_count = 0; sung_sign = 2; } } } // 준현이 매매방 if (today <= money_jun) { joo_jun += (int) (money_jun/today); money_jun -= today * (int)(money_jun/today); // System.out.println(joo_jun + " "+ money_jun); } // 성민이 매매 if (today <= money_sung && sung_count >= 2) { if (sung_sign == 1) { // 있던 거 다 팔아버 money_sung += today * joo_sung; joo_sung = 0; } else { // 최대한 살 수 있는만큼 영끌해서 사 joo_sung += (int) (money_sung/today); money_sung -= today * (int)(money_sung/today); } sung_sign = 0; sung_count = 0; } yesterday = today; } money_jun += today * joo_jun; money_sung += today * joo_sung; if (money_jun > money_sung) { System.out.println("BNP"); } else if (money_jun < money_sung) { System.out.println("TIMING"); } else { System.out.println("SAMESAME"); } } }
'얼렁뚱땅 JAVA 문제풀이' 카테고리의 다른 글
[JAVA 백준 문제풀이] 얼렁뚱땅 1717번 집합의 표현 풀이 (0) 2023.03.29 [JAVA 백준 문제풀이] 얼렁뚱땅 18258 큐2 풀이 (0) 2023.03.03 [JAVA 백준 문제풀이] 얼렁뚱땅 9012 괄호 풀이 (0) 2023.03.03 [JAVA] 전위순회로 사칙연산 계산하기 (0) 2023.03.02 [JAVA] 얼렁뚱땅 중위순회 풀이 (0) 2023.03.02