여니의 취준 준비/코딩테스트 (Java)

[SWEA] 1225번 [S/W 문제해결 기본] 7일차 - 암호생성기 in Java

여니's 2022. 8. 4. 13:18

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

 

SW Expert Academy

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

swexpertacademy.com


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
 
public class Solution {
    public static int[] array;
    private static boolean minus(int i) {
        if (array[0]-i<=0) {
            array[0]=0// 0보다 작거나 같은 경우 : 0으로 저장 
            return true;
        }
        else {
            array[0]-=i; // 0보다 큰 경우 : i만큼 감소
            return false;
        }
    }
    
    private static void move(int front) {
        for(int j=0; j<7; j++) {
            array[j]=array[j+1];
        }
        array[7]=front;
        return;
    }
    
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw= new BufferedWriter(new OutputStreamWriter(System.out));
        
        for(int t=1; t<=10; t++) {
            int test_case=Integer.parseInt(br.readLine());
            bw.write("#"+test_case+" ");
            StringTokenizer st = new StringTokenizer(br.readLine());
            array= new int[8];
            boolean button=false;
            for(int i=0; i<8; i++) {
                array[i]=Integer.parseInt(st.nextToken());
            }
            
            while (true) {
                for(int i=1; i<=5; i++) {
                    // 1. i만큼 감소
                    button= minus(i);
                    
                    // 2. 뒤로 이동
                    move(array[0]); 
                    
                    // 3. 암호 도출
                    if(button) break;
                    
                }
                if (button) break;
            }
            for(int j=0; j<8; j++) {
                bw.write(array[j]+"\t");
            }
            bw.write("\n");
        }
        bw.close();
    }
}
cs