20251026 baekjoon

This commit is contained in:
songyc macbook 2025-10-26 17:10:15 +09:00
parent 8bafde0fde
commit c3743b563b
6 changed files with 96 additions and 0 deletions

View File

@ -0,0 +1,9 @@
#include <stdio.h>
#include <stdlib.h>
int main() {
long long a, b;
scanf("%lld %lld",&a, &b);
printf("%lld\n",llabs(a-b));
return 0;
}

View File

@ -0,0 +1,11 @@
import java.util.*;
public class _2420 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long a = sc.nextLong();
long b = sc.nextLong();
System.out.println(Math.abs(a-b));
sc.close();
}
}

View File

@ -0,0 +1 @@
print(abs((lambda n: n[0]-n[1])(list(map(int, input().split())))))

View File

@ -0,0 +1,65 @@
if let n = Int(readLine() ?? ""),
let m = Int(readLine() ?? "")
{
var graph: [[(v: Int, w: Int)]] = Array(repeating: [], count: n+1)
for _ in 0..<m {
if let input = readLine(),
let nums = input.split(separator: " ").compactMap({Int($0)}) as? [Int],
nums.count == 3
{
let u = nums[0]
let v = nums[1]
let w = nums[2]
graph[u].append((v: v, w: w))
}
}
if let input = readLine(),
let start_end = input.split(separator: " ").compactMap({Int($0)}) as? [Int],
start_end.count == 2
{
let start = start_end[0]
let end = start_end[1]
var prev = Array(repeating: 0, count: n+1)
var qu: [(now: Int, distance: Int)] = []
var distance: [Int] = Array(repeating: Int.max, count: n+1)
qu.append((now: start, distance: 0))
distance[start] = 0
while !qu.isEmpty {
let current = qu.removeFirst()
if distance[current.now] < current.distance {
continue
}
for next in graph[current.now] {
if distance[next.v] > distance[current.now] + next.w {
distance[next.v] = distance[current.now] + next.w
prev[next.v] = current.now
qu.append((now: next.v, distance: distance[next.v]))
}
}
}
var path: [Int] = []
path.append(end)
while true {
let temp = path[path.count-1]
if prev[temp] == 0 {
break
}
path.append(prev[temp])
}
path.reverse()
print(distance[end])
print(path.count)
print(path.map({String($0)}).joined(separator: " "))
}
}

View File

@ -0,0 +1,5 @@
if let input = readLine(),
let nums = input.split(separator: " ").map({Int64($0)}) as? [Int64]
{
print(abs(nums[0]-nums[1]))
}

View File

@ -0,0 +1,5 @@
export {};
console.log(Math.abs(require("fs").readFileSync(0)
.toString().trim().split(" ").map(Number)
.reduce((acc,v,i) => i===0 ? acc-v : acc+v,0)
));