본문 바로가기
알고리즘/SWEA

[Java] SWEA 11387번 몬스터 사냥

by 컴공맨 2021. 2. 16.
 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com


풀이

N번 공격할 때마다 추가 공격력이 붙기 때문에 매번 공격할 때마다 추가 공격력을 계산해서 해결하였습니다.


코드

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

public class Solution {
	public static int D, L, N;
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder("");
		StringTokenizer st;
		
		int T = Integer.parseInt(br.readLine());
		for (int tc = 1; tc <= T; ++tc) {
			st = new StringTokenizer(br.readLine());
			D = Integer.parseInt(st.nextToken());
			L = Integer.parseInt(st.nextToken());
			N = Integer.parseInt(st.nextToken());
			
			int damage = 0;
			double percentage = L * 0.01;
			for (int i = 0; i < N; ++i) {
				damage += D * (1 + (i * (percentage)));
			}
			
			sb.append("#").append(tc).append(" ").append(damage).append("\n");
		}
		
		System.out.println(sb);
	}
}

 

pyo7410/Algorithm

1일 1커밋을 목표로! Contribute to pyo7410/Algorithm development by creating an account on GitHub.

github.com