From 4cf6d37a44f8bc413e22ee7a8e3084b4aefa93b7 Mon Sep 17 00:00:00 2001 From: SeongHoonC Date: Wed, 17 Jul 2024 10:54:27 +0900 Subject: [PATCH] 2024-07-17 solved --- SeongHoonC/README.md | 3 +- .../Diet.java" | 48 +++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 "SeongHoonC/\355\210\254\355\217\254\354\235\270\355\204\260/Diet.java" diff --git a/SeongHoonC/README.md b/SeongHoonC/README.md index 2ffc9642..ae21de87 100644 --- a/SeongHoonC/README.md +++ b/SeongHoonC/README.md @@ -31,5 +31,6 @@ | 27차시 | 2024.05.30 | 그래프 | 피리 부는 사나이 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/201 | | 28차시 | 2024.06.03 | 투포인터 | 부분합 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/205 | | 29차시 | 2024.07.01 | 구현, 그래프 | 서울의 지하철 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/213 | -| 30차시 | 2024.07.08 | 브루트포스 | 암호 만들기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/215 | +| 30차시 | 2024.07.08 | 브루트포스 | 암호 만들기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/215 | +| 31차시 | 2024.07.17 | 투포인터 | 다이어트 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/215 | --- diff --git "a/SeongHoonC/\355\210\254\355\217\254\354\235\270\355\204\260/Diet.java" "b/SeongHoonC/\355\210\254\355\217\254\354\235\270\355\204\260/Diet.java" new file mode 100644 index 00000000..df3d9491 --- /dev/null +++ "b/SeongHoonC/\355\210\254\355\217\254\354\235\270\355\204\260/Diet.java" @@ -0,0 +1,48 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + +import static java.lang.System.out; + +public class 다이어트 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + long g = Integer.parseInt(br.readLine()); + List list = new ArrayList(); + int head = 2; + int tail = 1; + + while (head >= tail && head < 987654321) { + // 제곱 빼기 제곱 계산 결과 + int x = (head + tail) * (head - tail); + + // g 보다 크다면 tail 을 증가시킴 + if (x > g) { + tail++; + continue; + } + + // g 보다 작다면 head 를 증가시킴 + if (x < g) { + head++; + continue; + } + + // g 랑 같으면 리스트에 집어넣음 + list.add(head); + tail++; + head++; + } + + // 없으면 -1 출력 + if (list.isEmpty()) { + out.println(-1); + return; + } + + // 있으면 순서대로 출력 + list.forEach(out::println); + } +} \ No newline at end of file