본문 바로가기

Algorithm/Algospot

[algospot]HOTSUMMER

문제

https://algospot.com/judge/problem/read/HOTSUMMER

더워서 에어컨 키고싶은데! 전력사용량 감축때문에 못키게한다!. 더워죽겠는데 전기를 못쓰게하니.. 전기사용감축정책이 잘 되고있는지 검사하는 프로그램을 만들자!

 

입력

첫째줄은 해당건물의 목표 전력사용량. 두번째줄은 각 시간대별로 전력사용량. 즉 9시부터 18시까지 사용량값 9개.

 

출력

시간대별 전력사용량 9개값을 더해서 목표전력사용량과 비교해서 사용량 이하일경우 "YES" 아니면 "NO"

 

풀이

시간대별 전력사용량 입력받은 값을 더해서 목표전력사용량과 비교한다.참 쉽죠?아직까지는;하핳하핳하하

 

package com.tutorial;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class HOTSUMMER {
    public static void main(String[] args)throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System. in));
        int cnt = Integer.parseInt(br.readLine());
        while (cnt -- > 0) {
            int target = Integer.parseInt(br.readLine());
            int sum = 0;
            String[] b = br.readLine().split(" ");
            for (int i = 0; i < b.length; i ++) 
                sum += Integer.valueOf(b[i]);
            
            System.out.println(
                (target >= sum)
                    ? "YES"
                    : "NO"
            );
        }
    }
}

 

'Algorithm > Algospot' 카테고리의 다른 글

[algospot]URI  (0) 2014.12.15
[algospot]XHAENEUNG  (0) 2014.12.11
[algospot]CONVERT  (0) 2014.12.11
[algospot]MISPELL  (0) 2014.12.11
[algospot]ENCRYPT  (0) 2014.12.11