本文整理汇总了Golang中fmt.Fscan函数的典型用法代码示例。如果您正苦于以下问题:Golang Fscan函数的具体用法?Golang Fscan怎么用?Golang Fscan使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了Fscan函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: main

func main() {
    //Enter your code here. Read input from STDIN. Print output to STDOUT
    var T, N, M, p1, p2 int
    io := bufio.NewReader(os.Stdin)
    fmt.Fscan(io, &T)
    for T > 0 {
        adjm := initialize(100, 6)
        fmt.Fscan(io, &N)
        for i := 0; i < N; i++ {
            fmt.Fscan(io, &p1, &p2)
            adjm[p1-1][p2-1] = 0
        }
        fmt.Fscan(io, &M)
        for i := 0; i < M; i++ {
            fmt.Fscan(io, &p1, &p2)
            adjm[p1-1][p2-1] = 0
            for j := 1; j <= 6; j++ {
                if (p1 - 1 + j) > 100-1 {
                    break
                }
                adjm[p1-1][p1-1+j] = 101
            }
        }
        dist := floydWarshall(adjm, 100)
        if dist[0][99] == 101 {
            fmt.Println("-1")
        } else {
            fmt.Println(dist[0][99])
        }
        T--
    }
}

开发者ID:pribadihcr,项目名称:hackerrank-go,代码行数:32,代码来源:snakesladders.go

示例2: GetUserAnswer

func (v Video) GetUserAnswer() int {
    var answer int
    stdin := bufio.NewReader(os.Stdin)
    fmt.Println("Title:", v.Title)
    fmt.Println("Description:", v.Description)

    fmt.Println("Available qualities: ")

    for i := 0; i < len(v.Links); i++ {
        fmt.Println(i+1, "Quality:", v.Links[i].Quality, "\tSize:", toMB(v.Links[i].Size), "MB")
    }

    fmt.Printf("Which quality do you want to donwload?")
    _, err := fmt.Fscan(stdin, &answer)
    stdin.ReadString('\n')

    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }

    for answer < 1 || answer > len(v.Links) {
        fmt.Printf("Invalid choice!")
        _, err := fmt.Fscan(stdin, &answer)
        stdin.ReadString('\n')

        if err != nil {
            fmt.Println(err)
            os.Exit(1)
        }
    }

    return answer
}

开发者ID:pluralism,项目名称:bliptv-downloader,代码行数:34,代码来源:video.go

示例3: DecodePolygon

// DecodePolygon loads a polygon saved using EncodePolygon function.
func DecodePolygon(in io.Reader) (*polyclip.Polygon, error) {
    var ncontours int
    _, err := fmt.Fscan(in, &ncontours)
    if err != nil {
        return nil, err
    }
    polygon := polyclip.Polygon{}
    for i := 0; i < ncontours; i++ {
        var npoints, level int
        _, err = fmt.Fscan(in, &npoints, &level)
        if err != nil {
            return nil, err
        }
        c := polyclip.Contour{}
        for j := 0; j < npoints; j++ {
            p := polyclip.Point{}
            _, err = fmt.Fscan(in, &p.X, &p.Y)
            if err != nil {
                return nil, err
            }
            if j > 0 && p.Equals(c[len(c)-1]) {
                continue
            }
            if j == npoints-1 && p.Equals(c[0]) {
                continue
            }
            c.Add(p)
        }
        if len(c) < 3 {
            continue
        }
        polygon.Add(c)
    }
    return &polygon, nil
}

开发者ID:sguzwf,项目名称:algorithm,代码行数:36,代码来源:encdec.go

示例4: reader

func reader() {
    file, err := os.Open("input.txt")
    if err != nil {
        panic(err)
    }
    defer file.Close()

    var scan struct {
        A, B float32
        C    bool
        D    string
    }

    log.Printf("scan: %v", scan)
    fmt.Fscan(file, &scan.A, &scan.B)
    log.Printf("scan: %v", scan)
    fmt.Fscan(file, &scan.C, &scan.D)
    log.Printf("scan: %v", scan)

    fmt.Fscanln(file, &scan.A, &scan.B, &scan.C, &scan.D)
    log.Printf("scan: %v", scan)

    fmt.Fscanf(file, "The Green %s %f %t %f", &scan.D, &scan.B, &scan.C, &scan.A)
    log.Printf("scan: %v", scan)
}

开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:25,代码来源:scanning.go

示例5: init

func init() {
    merkkiRuuduksi := map[rune]Ruutu{
        '#': Seinä,
        '.': Tyhjä,
        'o': Kivi,
        'x': Kuoppa,
        'p': Pelaaja,
        'm': Maali,
    }

    file, err := os.Open("testitaso.mp")
    if err != nil {
        panic("En saanut ladattua tasoa: " + err.Error())
    }

    fmt.Fscan(file, &kartanLeveys, &kartanKorkeus, &PelaajaX, &PelaajaY)

    kartta = make([]Ruutu, kartanLeveys*kartanKorkeus)
    for y := 0; y < kartanKorkeus; y++ {
        var rivi string
        fmt.Fscan(file, &rivi)
        for x, merkki := range rivi {
            LaitaKartanKohtaan(x, y, merkkiRuuduksi[merkki])
        }
    }
}

开发者ID:joonazan,项目名称:go-opas,代码行数:26,代码来源:kartta.go

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng