※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※

 

이번에 볼 문제는 백준 5292번 문제인 Counting Swann's Coins이다.
문제는 아래 링크를 확인하자.

https://www.acmicpc.net/problem/5292 

 

5292번: Counting Swann’s Coins

Governor Weatherby Swann orders you to count the number of coins in the government treasury. To make the job more interesting you decide to say ”Dead” for all numbers that are a multiple of 3 and ”Man” for all numbers that are a multiple of 5. For

www.acmicpc.net

1부터 N까지의 수를 반복문으로 돌아보며 15의 배수의 경우 DeadMan과 개행을, 그렇지 않은 3의 배수와 5의 배수의 경우 각각 "Dead", "Man"과 개행을, 나머지 수의 경우 그 정수와 공백을 출력하는 것으로 문제를 해결할 수 있다.

 

DeadMan 또한 한 단어임에 유의해 구현하자. 즉, DeadMan을 출력해야 할 때는 Dead와 Man 사이에 개행을 추가하면 안 된다.

 

아래는 제출한 소스코드이다.

#include <iostream>
using namespace std;

int N;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> N;
	for (int n = 1; n <= N; n++) {
		if (n % 15 == 0) cout << "DeadMan\n";
		else if (n % 3 == 0) cout << "Dead\n";
		else if (n % 5 == 0) cout << "Man\n";
		else cout << n << ' ';
	}
}
728x90

'BOJ' 카테고리의 다른 글

[BOJ 5360 // C++] Next Permutation  (0) 2022.12.22
[BOJ 15179 // C++] Golf Croquet  (0) 2022.12.22
[BOJ 10190 // C++] Acronyms  (0) 2022.12.22
[BOJ 6843 // C++] Anagram Checker  (0) 2022.12.22
[BOJ 5344 // C++] GCD  (0) 2022.12.22

+ Recent posts