SWEA

[SWEA] 증가하는 사탕 수열

itsnot4me 2024. 10. 25. 01:22

https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=3&contestProbId=AY4XhKTKU0IDFARM&categoryId=AY4XhKTKU0IDFARM&categoryType=CODE&problemTitle=&orderBy=FIRST_REG_DATETIME&selectCodeLang=ALL&select-1=3&pageSize=10&pageIndex=1

 

SW Expert Academy

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

swexpertacademy.com

class Solution
{
	public static void main(String args[]) throws Exception
	{
	
		Scanner sc = new Scanner(System.in);
		int T;
		T=sc.nextInt();
	
		for(int test_case = 1; test_case <= T; test_case++)
		{
			int A = sc.nextInt(); int B = sc.nextInt(); int C = sc.nextInt();
            int count = 0;
            
            while(C<=B){
                if(C<=2||B<=1) {
                    count=-1;
                    break;
                }            
                B--;
                count++;                  
            }
           	    while(B<=A){
                         if(B<=2||C<=1){
                             count =-1;
                             break;
                         }
                         if(A==1)
                            break;
                         A--;
                         count++;
                     }
            
			System.out.println("#" +  test_case + " " + count);
			
		}
	}
}

 

문제는 D3답지 않게 너무 쉽고, 예외 처리를 하는걸 굳이 신경을 쓴다면

1. C가 2 이하면 안됨

2. B가 1 이하면 안됨

3..A가 1이면 안됨, 그러나 count가 0인 경우 있으므로 그냥 탈출

'SWEA' 카테고리의 다른 글

[SWEA] 식료품 가게  (0) 2024.10.29
[SWEA] 회문의 회문  (0) 2024.10.28
[SWEA] 공평한 분배 2  (0) 2024.10.25
[SWEA] 어디에 단어가 들어갈 수 있을까 (+오답)  (0) 2024.10.15
[SWEA] 백만 장자 프로젝트 (+오답)  (0) 2024.10.13