Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
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
Archives
Today
Total
관리 메뉴

끄적끄적

SWE 암호생성기 본문

알고리즘

SWE 암호생성기

yenacathy97 2021. 8. 6. 21:26

큐를 이용하여 큐의 front 값을 변경하여 맨끝으로 삽입한다. 뺴주는 minus 변수가 5가 되면 다시 0으로 바꾸고 이러한 순환을 front에서 minus를 뺸값이 0보다 작을 때까지 반복한다.

package day0804;

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 Password {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub

		
		
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		
		for (int t = 1; t <= 10; t++) {
			int n = Integer.parseInt(bf.readLine());
			Queue<Integer> que = new LinkedList<>();
			String s = bf.readLine();
			StringTokenizer st= new StringTokenizer(s);
			int [] arr=new int[s.length()];
			while(st.hasMoreTokens()) {
				 que.add(Integer.parseInt(st.nextToken()));
			}
			int minus=1;
			while(true) {
				
				int first=que.poll();
				if(first-minus<=0) {
					que.add(0);
					break;
				}
				que.add(first-minus);
				if(minus==5) minus=0;

				minus++;
			}
			
			int index=0;
			System.out.print("#"+t+" ");
			while(!que.isEmpty()) {
				int temp=que.poll();
				System.out.print(temp+" ");
			}System.out.println();

		}

	}

}
Comments