20251115 baekjoon
This commit is contained in:
parent
45a1658511
commit
bc2418389d
31
code_study/Baekjoon/c/1247.c
Normal file
31
code_study/Baekjoon/c/1247.c
Normal file
@ -0,0 +1,31 @@
|
||||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
||||
10
code_study/Baekjoon/python/2166.py
Normal file
10
code_study/Baekjoon/python/2166.py
Normal file
@ -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))
|
||||
27
code_study/Baekjoon/swift/2467.swift
Normal file
27
code_study/Baekjoon/swift/2467.swift
Normal file
@ -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)
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user