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

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

示例1: main

func main() {
    in, _ := os.Open("544.in")
    defer in.Close()
    out, _ := os.Create("544.out")
    defer out.Close()

    var kase, n, r, l int
    var c1, c2 string
    first := true
    for {
        if fmt.Fscanf(in, "%d%d", &n, &r); n == 0 && r == 0 {
            break
        }
        if first {
            first = false
        } else {
            fmt.Fprintln(out)
        }
        matrix := make(map[string]map[string]int)
        for r > 0 {
            fmt.Fscanf(in, "%s%s%d", &c1, &c2, &l)
            if _, ok := matrix[c1]; !ok {
                matrix[c1] = make(map[string]int)
            }
            if _, ok := matrix[c2]; !ok {
                matrix[c2] = make(map[string]int)
            }
            matrix[c1][c2], matrix[c2][c1] = l, l
            r--
        }
        fmt.Fscanf(in, "%s%s", &c1, &c2)
        kase++
        fmt.Fprintf(out, "Scenario #%d\n%d tons\n", kase, floydWarshall(matrix, c1, c2))
    }
}

开发者ID:codingsince1985,项目名称:UVa,代码行数:35,代码来源:544.go

示例2: main

func main() {
    in, _ := os.Open("816.in")
    defer in.Close()
    out, _ := os.Create("816.out")
    defer out.Close()

    var n, f, token string
    var r1, c1, r2, c2 int
    var fm, to node
    for {
        if fmt.Fscanf(in, "%s", &n); n == "END" {
            break
        }
        fmt.Fscanf(in, "%d%d%s%d%d", &r1, &c1, &f, &r2, &c2)
        fm = node{r1, c1, toFace(f[0])}
        to = node{r2, c2, -1}
        maze = make(map[node][]node)
        for {
            if _, err := fmt.Fscanf(in, "%d%d", &r1, &c1); err != nil {
                break
            }
            var dir []string
            for {
                if fmt.Fscanf(in, "%s", &token); token == "*" {
                    break
                }
                dir = append(dir, token)
            }
            buildMaze(r1, c1, dir)
        }
        p := bfs(fm, to)
        output(out, n, p)
    }
}

开发者ID:codingsince1985,项目名称:UVa,代码行数:34,代码来源:816.go

示例3: main

func main() {
    in, _ := os.Open("429.in")
    defer in.Close()
    out, _ := os.Create("429.out")
    defer out.Close()

    var n int
    var word, fm, to string
    var dict map[string][]string
    fmt.Fscanf(in, "%d\n\n", &n)
    for i := 0; i < n; i++ {
        dict = make(map[string][]string)
        for {
            if fmt.Fscanf(in, "%s", &word); word == "*" {
                break
            }
            buildLink(dict, word)
        }
        for {
            if _, err := fmt.Fscanf(in, "%s%s\n", &fm, &to); err != nil {
                break
            }
            fmt.Fprintln(out, fm, to, bfs(dict, fm, to))
        }
    }
}

开发者ID:codingsince1985,项目名称:UVa,代码行数:26,代码来源:429.go

示例4: main

func main() {
    in, _ := os.Open("340.in")
    defer in.Close()
    out, _ := os.Create("340.out")
    defer out.Close()

    var n, kase int
    for {
        if fmt.Fscanf(in, "%d", &n); n == 0 {
            break
        }
        kase++
        fmt.Fprintf(out, "Game %d:\n", kase)
        s, g := make([]int, n), make([]int, n)
        for i := range s {
            fmt.Fscanf(in, "%d", &s[i])
        }
        for {
            stop := true
            for i := range g {
                fmt.Fscanf(in, "%d", &g[i])
                if g[i] != 0 {
                    stop = false
                }
            }
            if stop {
                break
            }
            strong, weak := match(s, g)
            fmt.Fprintf(out, "    (%d,%d)\n", strong, weak)
        }
    }
}

开发者ID:codingsince1985,项目名称:UVa,代码行数:33,代码来源:340.go

示例5: main

func main() {
    in, _ := os.Open("642.in")
    defer in.Close()
    out, _ := os.Create("642.out")
    defer out.Close()

    var word string
    dict := make(map[string]map[byte]int)
    for {
        if fmt.Fscanf(in, "%s", &word); word == "XXXXXX" {
            break
        }
        dict[word] = split(word)
    }
    for {
        if fmt.Fscanf(in, "%s", &word); word == "XXXXXX" {
            break
        }
        if matched := find(word, dict); len(matched) == 0 {
            fmt.Fprintln(out, "NOT A VALID WORD")
        } else {
            fmt.Fprintln(out, strings.Join(matched, "\n"))
        }
        fmt.Fprintln(out, "******")
    }
}

开发者ID:codingsince1985,项目名称:UVa,代码行数:26,代码来源:642.go

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