From bc2418389dbd3eb24bde9201063461f2b12c4413 Mon Sep 17 00:00:00 2001 From: songyc macbook Date: Sat, 15 Nov 2025 21:35:04 +0900 Subject: [PATCH] 20251115 baekjoon --- code_study/Baekjoon/c/1247.c | 31 ++++++++++++++++++++++++++++ code_study/Baekjoon/python/2166.py | 10 +++++++++ code_study/Baekjoon/swift/2467.swift | 27 ++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 code_study/Baekjoon/c/1247.c create mode 100644 code_study/Baekjoon/python/2166.py create mode 100644 code_study/Baekjoon/swift/2467.swift diff --git a/code_study/Baekjoon/c/1247.c b/code_study/Baekjoon/c/1247.c new file mode 100644 index 0000000..be11d36 --- /dev/null +++ b/code_study/Baekjoon/c/1247.c @@ -0,0 +1,31 @@ +#include + +char get_sign(long long val, int overflow_count) { + if(overflow_count > 0) return '+'; + if(overflow_count < 0) return '-'; + return val == 0 ? '0' : val < 0 ? '-' : '+'; +} + +int main() { + int i = 3; + + while(i--) { + int T; + scanf("%d",&T); + + long long sum = 0; + int overflow = 0; + + while(T--) { + long long n, prev = sum; + scanf("%lld", &n); + sum += n; + if(n > 0 && prev > 0 && sum < 0) overflow++; + else if(n < 0 && prev < 0 && sum > 0) overflow--; + } + + printf("%c\n",get_sign(sum, overflow)); + } + + return 0; +} \ No newline at end of file diff --git a/code_study/Baekjoon/python/2166.py b/code_study/Baekjoon/python/2166.py new file mode 100644 index 0000000..131b5de --- /dev/null +++ b/code_study/Baekjoon/python/2166.py @@ -0,0 +1,10 @@ +axis = [] +for _ in range(int(input())) : + axis.append(tuple(map(int, input().split()))) +axis.append(axis[0]) + +area = 0 +for i in range(len(axis)-1) : + area += axis[i][0]*axis[i+1][1] - axis[i][1]*axis[i+1][0] + +print(round(abs(area)*0.5,1)) \ No newline at end of file diff --git a/code_study/Baekjoon/swift/2467.swift b/code_study/Baekjoon/swift/2467.swift new file mode 100644 index 0000000..59bb193 --- /dev/null +++ b/code_study/Baekjoon/swift/2467.swift @@ -0,0 +1,27 @@ +if let N = Int(readLine() ?? ""), + let line = readLine(), + let nums = line.split(separator: " ").compactMap({Int($0)}) as? [Int], + nums.count == N +{ + var (L, R) = (0, N-1) + var (vL, vR) = (nums[L], nums[R]) + var val = abs(vL + vR) + + while L != R { + let temp = nums[L] + nums[R] + + if val > abs(temp) { + (vL, vR) = (nums[L], nums[R]) + val = abs(temp) + } + + if temp > 0 { + R -= 1 + } + else { + L += 1 + } + } + + print(vL, vR) +}