hojongs / algorithm

A set of source codes to solve algorithm written in python
3 stars 0 forks source link

BOJ Utils #117

Open hojongs opened 2 years ago

hojongs commented 2 years ago

Python

"""
n = int(readl())
nums = [int(i) for i in readl().split()]
nums = [int(readl()) for _ in range(n)]
lines = [readl().rstrip() for _ in range(n)]
rows = [[int(i) for i in readl().split()] for _ in range(n)]
s = readl().rstrip()
"""
import sys
readl = sys.stdin.readline

Go

readString

var reader = bufio.NewReader(os.Stdin)
var s string

func readString() {
    delim := "\n"
    if os.Getenv("OS") == "WINDOWS_NT" {
        delim = "\r\n"
    }
    s, _ = reader.ReadString('\n')
    s = strings.TrimSuffix(s, delim)
}

func main() {
    readString()
}

readInt

var reader = bufio.NewReader(os.Stdin)
var n int

func readInt(a *int) {
    fmt.Fscan(reader, a)
}

func main() {
    readInt(&n)
}

readIntArray

var reader = bufio.NewReader(os.Stdin)
var n int
var nums [10000]int

func readInt(a *int) {
    fmt.Fscan(reader, a)
}

func readIntArray(n int) {
    for i := 0; i < n; i++ {
        fmt.Fscan(reader, &nums[i])
    }
}

func main() {
    readInt(&n)
    readIntArray(n)
}

printlnIntArray

func printlnIntArray(nums []int, sep string) {
    num_strs := make([]string, len(nums))
    for i := 0; i < n; i++ {
        num_strs[i] = strconv.Itoa(nums[i])
    }
    fmt.Println(strings.Join(num_strs, sep))
}
dangddoong commented 1 year ago

당케