Algorithm/SWEA

[swexpert] 1225. 암호생성기

반응형

[swexpert] 1225. 암호생성기


문제 출처 : https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV14uWl6AF0CFAYD&categoryId=AV14uWl6AF0CFAYD&categoryType=CODE




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
import java.util.Scanner;
 
public class SW문제해결_암호생성기 {
 
    static int[] arr = new int[10];
    
    public static void cycle(int[] a) { // cycle 함수
        
        boolean c = true;
        
        for (int i = 1; i <= 5; i++) {
            
            if(a[0>= 0) { // 첫번째 배열이 0보다 클 때만 진행
                a[0-= i;
                if(a[0< 0) a[0= 0;
                a[8= a[0];
                
                for (int j = 0; j < 8; j++) { // 배열 왼쪽 한칸 shift
                    a[j] = a[j+1];
                }
                
                if(a[7== 0) { // 암호생성 끝나면  break
                    c = false;
                    break;
                }
                
            }
        }
        if(c) // 안끝나면 cycle 반복
            cycle(a);
    }
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        for (int i = 1; i <= 10; i++) {
            
            int ts = sc.nextInt();
            
            for (int j = 0; j < 8; j++) {
                arr[j] = sc.nextInt();
            }
            
            cycle(arr);
            
            System.out.print("#" + i + " ");
            for (int j = 0; j < 8; j++) {
                System.out.print(arr[j] + " ");
            }
            System.out.println();
        }
    }
 
}
cs


반응형

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

[swexpert] 1228. 암호문1  (0) 2019.01.29
[swexpert] 1210. Ladder1  (0) 2019.01.14
[swexpert] 1206. View  (0) 2019.01.11
[swexpert] 5431. 민석이의과제체크하기  (0) 2019.01.08
[swexpert] 1208. Flatten  (0) 2019.01.08