728x90
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com

방법2
import java.util.Scanner;
class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int tc = 1; tc <= t; tc++) {
int n = sc.nextInt();
int b = sc.nextInt();
int e = sc.nextInt();
int result = 0;
for (int i = 0; i < n; i++) {
int sand = sc.nextInt();
for (int j = b - e; j <= b + e; j++) {
if (j % sand == 0) {
result++;
break;
}
}
}
System.out.println("#" + tc + " " + result);
}
}
}
방법1
import java.util.Scanner;
class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int tc=1;tc<=t;tc++) {
int n = sc.nextInt();
int b = sc.nextInt();
int e = sc.nextInt();
boolean isPossible=false;
int result=0;
for(int i=0;i<n;i++) {
isPossible=false;
int sand = sc.nextInt();
int idx=1;
int ans=sand*idx;
while(ans<=b+e) {
if(ans>=b-e&&ans<=b+e) {
isPossible=true;
break;
}
ans = sand*idx++;
}
if(isPossible) {
result++;
}
}
System.out.println("#"+tc+" "+result);
}
}
}728x90
'SW Expert Academy > SWEA D3' 카테고리의 다른 글
| [SW Expert Academy] 민정이와 광직이의 알파벳 공부 (D3) (0) | 2024.10.01 |
|---|---|
| [SW Expert Academy] 숫자가 같은 배수 (D3) (0) | 2024.10.01 |
| [SW Expert Academy] 진용이네 주차타워 (D3) (0) | 2024.10.01 |
| [SW Expert Academy] 조 만들기 (D3) (0) | 2024.10.01 |
| [SW Expert Academy] 파도반 수열 (D3) (0) | 2024.09.29 |