20251026 baekjoon
This commit is contained in:
parent
8bafde0fde
commit
c3743b563b
9
code_study/Baekjoon/c/2420.c
Normal file
9
code_study/Baekjoon/c/2420.c
Normal 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;
|
||||
}
|
||||
11
code_study/Baekjoon/java/_2420.java
Normal file
11
code_study/Baekjoon/java/_2420.java
Normal 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();
|
||||
}
|
||||
}
|
||||
1
code_study/Baekjoon/python/2420.py
Normal file
1
code_study/Baekjoon/python/2420.py
Normal file
@ -0,0 +1 @@
|
||||
print(abs((lambda n: n[0]-n[1])(list(map(int, input().split())))))
|
||||
65
code_study/Baekjoon/swift/11779.swift
Normal file
65
code_study/Baekjoon/swift/11779.swift
Normal 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: " "))
|
||||
}
|
||||
}
|
||||
5
code_study/Baekjoon/swift/2420.swift
Normal file
5
code_study/Baekjoon/swift/2420.swift
Normal 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]))
|
||||
}
|
||||
5
code_study/Baekjoon/ts/2420.ts
Normal file
5
code_study/Baekjoon/ts/2420.ts
Normal 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)
|
||||
));
|
||||
Loading…
x
Reference in New Issue
Block a user