상세 컨텐츠

본문 제목

[코드트리] 순위경쟁2

💯ProblemSolving/문제 풀이

by :Eundms 2024. 10. 7. 21:15

본문

https://www.codetree.ai/missions/5/problems/ranking-competition2?&utm_source=clipboard&utm_medium=text

 

코드트리 | 코딩테스트 준비를 위한 알고리즘 정석

국가대표가 만든 코딩 공부의 가이드북 코딩 왕초보부터 꿈의 직장 코테 합격까지, 국가대표가 엄선한 커리큘럼으로 준비해보세요.

www.codetree.ai

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	static int N; // 점수 변동 목록의 수
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		N = Integer.parseInt(br.readLine());
		
		int diffCnt = 0;
		int aScore = 0, bScore = 0;
		for(int i = 0; i < N; i++) {
			StringTokenizer st = new StringTokenizer(br.readLine());
			char C = st.nextToken().charAt(0); // A, B
			int S = Integer.parseInt(st.nextToken()); // 점수 변동값
			
			int nextA = aScore, nextB = bScore; // 이부분에 대한 처리를 잘못해서 틀렸었음
			if (C == 'A') {
				nextA += S; 
			} else {
				nextB += S;
			}
			
			if(status(nextA, nextB)!= status(aScore, bScore)) {
				diffCnt += 1;
			}
			
			aScore = nextA;
			bScore = nextB;
		}
		System.out.println(diffCnt);
		

	}  
	static int status(int a, int b) {
		if(a > b) {
			return 1;
		} else if(a < b) {
			return 2;
		}
		return 3;
	}

}
728x90

'💯ProblemSolving > 문제 풀이' 카테고리의 다른 글

[코드트리] 다수의 객체 이동  (5) 2024.10.10
[코드트리] 오목  (0) 2024.10.09
[BJ] 1182 : 부분수열의 합  (0) 2024.10.05
[SWEA] 4408. 자기 방으로 돌아가기  (0) 2024.10.01
[SWEA] 1211. ladder2  (0) 2024.10.01

관련글 더보기

댓글 영역