본문 바로가기

알고리즘/수학문제6

[백준] 2003번 수들의 합 2 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()," "); int n = Integer.parseInt(st.nextToken()); int m = Integer.parse.. 2022. 5. 23.
[백준] 18870번 좌표 압축 #Java 1. 복사 배열을 만든다. 2. 순회하면서 값과 인덱스를 저장하는 해시맵을 구성한다. 3. 해당 값을 꺼내 출력한다. import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); HashMap hashMap = new HashMap(); int n = Integer.parseInt(br.readLine()); int [] answer = new int [n]; StringTokenizer st = new StringTokenize.. 2022. 5. 22.
[프로그래머스] 약수의 개수와 덧셈 #Java import java.io.IOException; import java.util.*; class Main { public static void main(String[] args) throws IOException { int l = 13; int r = 17; System.out.println(solution(l,r)); } public static int solution(int left, int right) { int answer = 0; for (int i = left; i 2022. 5. 20.
[프로그래머스] 없는 숫자 더하기 #Java import java.io.IOException; import java.util.*; class Main { public static void main(String[] args) throws IOException { int [] arr = {1,2,3,4,6,7,8,0}; System.out.println(solution(arr)); System.out.println(solution2(arr)); } public static int solution(int[] numbers) { int answer = 0; int [] ans = new int[10]; for (int i = 0; i < numbers.length; i++) { ans[numbers[i]]++; } for (int i = 0; i < an.. 2022. 5. 20.