Skip to content

Latest commit

 

History

History
56 lines (44 loc) · 867 Bytes

File metadata and controls

56 lines (44 loc) · 867 Bytes

Staircase

golang

package main

import (
    "bufio"
    "fmt"
    "io"
    "os"
    "strconv"
    "strings"
)

// Complete the staircase function below.
func staircase(n int32) {
    for i := 1; i <= int(n); i++ {
        for j := 0; j < int(n) - i; j++ {
            fmt.Print(" ")
        }

        for j := 0; j < i; j++ {
            fmt.Print("#")
        }

        fmt.Println()
    }
}

func main() {
    reader := bufio.NewReaderSize(os.Stdin, 1024 * 1024)

    nTemp, err := strconv.ParseInt(readLine(reader), 10, 64)
    checkError(err)
    n := int32(nTemp)

    staircase(n)
}

func readLine(reader *bufio.Reader) string {
    str, _, err := reader.ReadLine()
    if err == io.EOF {
        return ""
    }

    return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
    if err != nil {
        panic(err)
    }
}