알고리즘 단련장/소프티어

[소프티어] 위험한 효도 레벨1 자바 풀이

snapcoder 2024. 7. 17. 23:16
728x90
반응형
SMALL

https://softeer.ai/practice/7368

 

Softeer - 현대자동차그룹 SW인재확보플랫폼

 

softeer.ai

 

 

 

 

텍스트로 적혀져있는 레벨은 1.

그림 레벨은 2.

뭔가 수상한 문제였다.

 

 

 

 

정답률은 높았는데

다들 검색해서 오히려 정답을 밀어넣은 것일까?

 

 

27번째줄이 함정인 것 같다.

꽤나 오래 검토하고 생각했던 부분이다.

두번째 케이스가 도움이 됐다.

a,b와 b,a가 바뀌는 순간을 잘 체크해야 한다.

            if(totalPos == d){
                continue;
            }

 

 

 

아무튼 정답

import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        StringTokenizer st = new StringTokenizer(br.readLine());
        //int n = Integer.parseInt(br.readLine());
        int a = Integer.parseInt(st.nextToken());
        int b = Integer.parseInt(st.nextToken());
        int d = Integer.parseInt(st.nextToken());

        int x = a;
        int y = b;

        int cnt = 0;
        int tempPos = 0;
        int totalPos = 0;
        while(totalPos != d){
            
            tempPos++;
            totalPos++;
            cnt++;
            // System.out.println(x +" "+ y +" "+ d +" "+ tempPos+" "+ totalPos +" "+ cnt);
            if(totalPos == d){
                continue;
            }
            if(x <= tempPos){
                tempPos = 0;
                cnt+= y;
            }
        }
        int rx = b;
        int ry = a;

        tempPos = 0;
        totalPos = 0;
        while(totalPos != d){
            tempPos++;
            totalPos++;
            cnt++;
            // System.out.println(rx +" "+ ry +" "+ d +" "+ tempPos +" "+ totalPos +" "+ cnt);
            if(totalPos == d){
                continue;
            }
            if(rx <= tempPos){
                tempPos = 0;
                cnt+= ry;
            }
            
        }
        
        bw.write(String.valueOf(cnt));
        bw.close();
    }
}
728x90
반응형
LIST