백준 3052번 www.acmicpc.net/problem/3052
풀이
Collection 두 개를 이용해서 input arraylist 에는 입력값을 받고, remainder arraylist 에는 42로 나눈 나머지 값을 받았다. 중첩 for문을 이용해서 remainder 의 인덱스 값이 그 후의 인덱스 값과 동일한 경우에는 cnt를 증가시켰다.이 때, 입력값과 동일하게 나올 수 있는 나머지 값이 총 10개 이므로 10개에서 이 cnt 를 제외한 값을 정답으로 출력했다.(구하고자 하는 값은 서로 다른 나머지 수이기 때문에)
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
|
import java.util.*;
public class Array_3052 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
List<Integer> input = new ArrayList<>();
List<Integer> remainder = new ArrayList<>();
int cnt = 0;
for (int i=0; i<10; i++) {
input.add(sc.nextInt());
remainder.add(input.get(i)%42);
}
sc.nextLine();
for (int i=0; i<remainder.size()-1; i++) {
for (int j=i+1; j<remainder.size(); j++) {
if(remainder.get(i)==remainder.get(j)) {
cnt++;
break;
}
}
}
System.out.println(10-cnt);
sc.close();
}
}
|
cs |
'알고리즘과 코테' 카테고리의 다른 글
[Java | 백준 2941] 크로아티아 알파벳 (0) | 2021.03.18 |
---|---|
[Java | 백준 1152] 단어의 개수 (0) | 2021.03.18 |
[JAVA | 백준 2562] 최댓값 (0) | 2021.03.17 |
[JAVA | 백준 10818] 최대, 최소 (0) | 2021.03.17 |
[Java | 백준 1546] 평균 (0) | 2021.03.17 |
댓글
최근에 올라온 글
TAG
- 독서후기
- 노마드코더
- AWS
- gradle build
- 개발도서
- intellij
- 정보처리기사
- 노개북
- 오늘의코딩
- filezila
- 정보처리기사 실기
- 북클럽
- 배포
- IT 5분 잡학사전
- 기술블로그
- 웹페이지만들기
- gradle
- JIRA
- 정보처리기사 필기
- git연동
- jdbc
- 실용주의프로그래머
- java
- LifecycleException
- SQLD
- 호스팅영역
- putty
- ubuntu
- spring
- EC2
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함