최's 먹공로그
SW expert Academy 1225_[S/W 문제해결 기본]7일차_암호생성기 본문
https://www.swexpertacademy.com/main/code/problem/problemDetail.do
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 |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;
public class Solution_1225_SW문제해결기본7일차_암호생성기_최성호 {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
Queue<Integer> q = new LinkedList<Integer>();
int[] arr = new int[8];
int cha = 1;
int num = 0;
String str2 = "";
for(int i = 0; i < 10; i++) { // test case 10번 반복
q.clear(); // test case마다 초기화
str2 = "";
cha = 1;
int tc = Integer.parseInt(bf.readLine()); // test case
String str = bf.readLine(); // 9550 9556 9550 9553 9558 9551 9551 9551 한줄로 받음
String[] st = str.split(" "); // 공백을 기준으로 나눠서 st라는 String 배열에 넣기
for(int j = 0; j < 8; j++) {
q.add(Integer.parseInt(st[j])); // q를 이용하기 위해
}
while(true) {
num = q.poll(); // q에서 첫 값을 꺼냄
num = num - cha; // num에서 cha(1~5) 값을 차례로 빼줌
cha++;
if(num <= 0) {
q.add(0); // num이 0보다 작거나 같아지는 순간 q끝에 0을 add해줌
break;
}
q.add(num); // num<=0이 아닌경우에는 num-cha한 값을 q끝에 계속 add해줌
if(cha == 6) cha = 1; // cha가 6이 되는 순간 다시 1로 세팅
}
for (int j = 0; j < 8; j++) { // 출력 편하게 하기 위해서
str2 += q.poll() + " ";
}
System.out.println("#" + tc + " " + str2);
}
}
}
|
cs |
'APS' 카테고리의 다른 글
SW expert Academy 3456_직사각형 길이 찾기 (2) | 2019.02.03 |
---|---|
SW expert Academy 1859_백만 장자 프로젝트 (0) | 2019.02.03 |
SW expert Academy 1224_[S/W 문제해결 기본]6일차_계산기3 (0) | 2019.02.03 |
SW expert Academy 1223_[S/W 문제해결 기본]6일차_계산기2 (0) | 2019.02.03 |
SW expert Academy 1218_[S/W 문제해결 기본] 4일차_괄호 짝짓기 (0) | 2019.02.03 |