목록Algorithm (127)
main
* Interface Comparable, copareTo method override 하여 좌표를 정렬하였다. import java.io.*; import java.util.*; public class Main { private static class Point implements Comparable { int x; int y; public Point(int x, int y) { this.x = x; this.y = y; } public Integer getX() { return this.x; } public Integer getY() { return this.y; } @Override public boolean equals(Object o) { Point p = (Point) o; return p.g..
* 오름차순으로 정렬한 다음, stringbuffer로 reverse 해주었다. import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); char[] arr = br.readLine().toCharArray(); Arrays.sort(arr); StringBuffer sb = new StringBuffer(String.valueOf(arr)); System.out.println(sb.reverse().toString());..
* x, y 좌표가 2개씩 같아야 함. * HashMap 사용 - key값에 좌표 값, value 값이 빈도 수 입력 * 람다식 사용해서 HashMap foreach import java.io.*; import java.util.*; public class Main { public static class Point { int x; int y; public Point(int x, int y) { this.x = x; this.y = y; } } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); Map xMap = new..
* 유클리드 호제법 두 양의 정수 a, b (a>b)에 대하여 a=bq+r이라 하면, (a, b)의 최대공약수는 (b,r)의 최대공약수와 같다. r==0 일 때, 두 수의 최대공약수는 b이다. 최소 공배수 = a * b / 최대공약수 * 최대공약수 * 최소공배수 import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int N = Integer.parseInt(br.readLine()); for (int i = 0; i ..
* stack 구조라고 생각하고 풀었다. * count > 0 이면서 count ==0 으로 끝나야 함. import java.io.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int N = Integer.parseInt(br.readLine()); for (int i = 0; i < N; i++) { int count = 0; char[] str = br.readLine().toCharArray(); for (char c : str) { if (count < 0) { b..