[SWEA] C++ 1225. [S/W 문제해결 기본] 7일차 - 암호생성기(D3)

swb·2022년 11월 14일
0

SWEA

목록 보기
3/19

문제 바로가기

접근 방법

  1. 꺼내서 이동하는 건 보통 큐가 편하다.
  2. 큐에 입력 받은 값들을 넣어준다.
  3. 맨 앞에서부터 1~5를 빼주고 pop하여 뒤로 푸시하고 이러한 과정을 반복한다.
  4. D3 치고는 쉬운 편이다.

풀이

#include <iostream>
#include <string>
#include <queue>
#define MAX 8
using namespace std;

int test_case = 10, number, j;
queue<int> q;

void input() {
	int num;

	for (int i = 0; i < MAX; i++) {
		cin >> num;
		q.push(num);
	}
}

void create_password() {
	j = 1;
	while (1) {
		if (j == 6) j = 1;

		int temp = q.front();

		q.pop();

		if (temp - j <= 0) {
			q.push(0);
			break;
		}

		q.push(temp - j);
		j++;
	}
}

void print(int i) {
	cout << "#" << i << " ";
	while (!q.empty()) {
		cout << q.front() << " ";
		q.pop();
	}
	cout << "\n";
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	for (int i = 1; i <= test_case; i++) {
		cin >> number;

		input(); // 8개의 숫자 입력 받기
		create_password(); // 암호 생성
		print(i); // 출력
	}

	return 0;
}
profile
개발 시작

0개의 댓글