🔻PS/Baekjoon

[Baekjoon] 백준 4504 배수 찾기 C++

_니지 2022. 10. 21. 17:02

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

 

4504번: 배수 찾기

첫째 줄에 n이 주어진다. 다음 줄부터 한 줄에 한 개씩 목록에 들어있는 수가 주어진다. 이 수는 0보다 크고, 10,000보다 작다. 목록은 0으로 끝난다.

www.acmicpc.net

 

문제

정수 n(0 < n < 1000)과 수의 목록이 주어졌을 때, 목록에 들어있는 수가 n의 배수인지 아닌지를 구하는 프로그램을 작성하시오.

입력

첫째 줄에 n이 주어진다. 다음 줄부터 한 줄에 한 개씩 목록에 들어있는 수가 주어진다. 이 수는 0보다 크고, 10,000보다 작다. 목록은 0으로 끝난다.

출력

목록에 있는 수가 n의 배수인지 아닌지를 구한 뒤 예제 출력처럼 출력한다.

예제 입력 1 

3
1
7
99
321
777
0

예제 출력 1 

1 is NOT a multiple of 3.
7 is NOT a multiple of 3.
99 is a multiple of 3.
321 is a multiple of 3.
777 is a multiple of 3.

 

코드

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
using namespace std;
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cmath>
#include <map>
#include <set>
#define _CRT_SECURE_NO_WARNINGS
#define INF 987654321
#define ll long long
typedef pair<intint> PII;
 
 
 
int main() {
    int num;
    cin >> num;
 
    while (true) {
        int target;
        cin >> target;
 
        if (target == 0break;
 
        if (target % num == 0) {
            cout << target << " is a multiple of " << num << ".\n";
        }
        else {
            cout << target << " is NOT a multiple of " << num << ".\n";
        }
    }
 
 
    return 0;
}
cs

 

728x90
반응형