Skip to content

Commit

Permalink
Merge pull request #219 from AlgoLeadMe/31-SeongHoonC
Browse files Browse the repository at this point in the history
31-SeongHoonC
  • Loading branch information
SeongHoonC authored Jul 22, 2024
2 parents 2472c41 + 4cf6d37 commit b0ec1d1
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
3 changes: 2 additions & 1 deletion SeongHoonC/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@
| 27์ฐจ์‹œ | 2024.05.30 | ๊ทธ๋ž˜ํ”„ | <a href="https://www.acmicpc.net/problem/16724">ํ”ผ๋ฆฌ ๋ถ€๋Š” ์‚ฌ๋‚˜์ด</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/201 |
| 28์ฐจ์‹œ | 2024.06.03 | ํˆฌํฌ์ธํ„ฐ | <a href="https://www.acmicpc.net/problem/1806">๋ถ€๋ถ„ํ•ฉ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/205 |
| 29์ฐจ์‹œ | 2024.07.01 | ๊ตฌํ˜„, ๊ทธ๋ž˜ํ”„ | <a href="https://www.acmicpc.net/problem/16166">์„œ์šธ์˜ ์ง€ํ•˜์ฒ </a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/213 |
| 30์ฐจ์‹œ | 2024.07.08 | ๋ธŒ๋ฃจํŠธํฌ์Šค | <a href="https://www.acmicpc.net/problem/1759">์•”ํ˜ธ ๋งŒ๋“ค๊ธฐ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/215 |
| 30์ฐจ์‹œ | 2024.07.08 | ๋ธŒ๋ฃจํŠธํฌ์Šค | <a href="https://www.acmicpc.net/problem/1759">์•”ํ˜ธ ๋งŒ๋“ค๊ธฐ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/215 |
| 31์ฐจ์‹œ | 2024.07.17 | ํˆฌํฌ์ธํ„ฐ | <a href="https://www.acmicpc.net/problem/1484">๋‹ค์ด์–ดํŠธ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/215 |
---
48 changes: 48 additions & 0 deletions SeongHoonC/ํˆฌํฌ์ธํ„ฐ/Diet.java
Original file line number Diff line number Diff line change
@@ -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<Integer> list = new ArrayList<Integer>();
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);
}
}

0 comments on commit b0ec1d1

Please sign in to comment.