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

 

이번에 볼 문제는 백준 24408번 문제인 Mult!이다.
문제는 아래 링크를 확인하자.

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

 

24408번: Mult!

The first line of input contains an integer $n$, $2 ≤ n ≤ 1\,000$, the length of the number sequence. The following $n$ lines contains the sequence, one number per line. All numbers in the sequence are positive integers less than or equal to $100$. Th

www.acmicpc.net

N개의 숫자를 읽는 동안, (남은 숫자가 있다면) 숫자 하나 f를 먼저 읽고, f의 배수가 나올 때까지 다음 수를 찾다가 f의 배수가 나오면 그 수를 출력, (남은 숫자가 있다면) f를 갱신하고 위의 과정을 반복한다.

 

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

#include <iostream>
using namespace std;

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

	int N; cin >> N;
	int f; cin >> f;
	for (int i = 1; i < N; i++) {
		int x; cin >> x;
		if (x % f == 0) {
			cout << x << '\n';
			i++;
			if (i < N) cin >> f;
		}
	}
}
728x90

'BOJ' 카테고리의 다른 글

[BOJ 24900 // C++] 한별 찍기  (0) 2022.04.17
[BOJ 23397 // C++] Katmandu  (0) 2022.04.17
[BOJ 24930 // C++] Ordinary Ordinals  (0) 2022.04.17
[BOJ 23854 // C++] The Battle of Giants  (0) 2022.04.17
[BOJ 24793 // C++] Shiritori  (0) 2022.04.17

+ Recent posts