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

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

示例1: main

func main() {
    var n int
    data, err := os.Open(os.Args[1])
    if err != nil {
        log.Fatal(err)
    }
    defer data.Close()
    scanner := bufio.NewScanner(data)
    for scanner.Scan() {
        t := strings.Split(scanner.Text(), ";")
        u := strings.Split(t[0], ",")
        fmt.Sscan(t[1], &n)
        v, vk := make(map[int]bool, len(u)), make([]int, len(u))
        for i := range u {
            var w int
            fmt.Sscan(u[i], &w)
            v[w], vk = true, append(vk, w)
        }
        f := false
        for _, i := range vk {
            if 2*i < n && v[n-i] {
                if f {
                    fmt.Print(";")
                }
                fmt.Print(i, ",", n-i)
                f = true
            }
        }
        if !f {
            fmt.Print("NULL")
        }
        fmt.Println()
    }
}

开发者ID:oorja,项目名称:ce-challenges,代码行数:34,代码来源:number_pairs.go

示例2: sLane

func sLane(in string) string {
    var n, t int
    _, err := fmt.Sscan(in, &n, &t)
    if err != nil {
        return ""
    }
    fmt.Printf("n = %d, t = %d\n", n, t)
    w := make([]int, n)
    for i := 0; i < n; i += 2 {
        var f int
        _, err := fmt.Sscan(in[i+3:], &f)
        if err != nil {
            return ""
        }
        w = append(w, f)
    }

    v := make(TestCases, t)
    for z := 0; z < t; z++ {
        var tc TestCase
        _, err := fmt.Sscan(in[z+(n*2)+2:], &tc.Entry, &tc.Exit)
        if err != nil {
            return ""
        }
        v[z] = tc
    }
    fmt.Printf("%#v\n", v)

    for z := 0; z < len(v); z++ {

    }
    return ""
}

开发者ID:JonPulfer,项目名称:hackerrank,代码行数:33,代码来源:servicelane.go

示例3: intersect

func intersect(s, t string) string {
    var (
        a    int
        x, y []int
        r    []string
    )
    u, v := strings.Split(s, ","), strings.Split(t, ",")
    for _, i := range u {
        fmt.Sscan(i, &a)
        x = append(x, a)
    }
    for _, i := range v {
        fmt.Sscan(i, &a)
        y = append(y, a)
    }
    for i, j := 0, 0; i < len(u) && j < len(v); {
        if x[i] == y[j] {
            r = append(r, fmt.Sprint(x[i]))
            i++
            j++
        } else if x[i] > y[j] {
            j++
        } else {
            i++
        }
    }
    return strings.Join(r, ",")
}

开发者ID:nikai3d,项目名称:ce-challenges,代码行数:28,代码来源:intersection.go

示例4: main

func main() {
    scanner := bufio.NewScanner(os.Stdin)

    // width: the number of cells on the X axis
    var width int
    scanner.Scan()
    fmt.Sscan(scanner.Text(), &width)

    // height: the number of cells on the Y axis
    var height int
    scanner.Scan()
    fmt.Sscan(scanner.Text(), &height)

    node := make([][]bool, height) //slice for nodes' rows

    for i := 0; i < height; i++ {
        node[i] = make([]bool, width) //slice - nodes' row
    }

    for i := 0; i < height; i++ { //find nodes
        scanner.Scan()
        line := scanner.Text() // width characters, each either 0 or .
        for j := 0; j < len(line); j++ {
            if string(line[j]) == "0" {
                node[i][j] = true
            }
        }
    }

    for i := 0; i < height; i++ {
        for j := 0; j < width; j++ {
            if node[i][j] { //is there a node?
                res := strconv.Itoa(j) + " " + strconv.Itoa(i) + " " //start of response
                for k := j + 1; k < width; k++ {
                    if node[i][k] { //is there a node?
                        res += strconv.Itoa(k) + " " + strconv.Itoa(i) + " " //inner response
                        break
                    }
                }
                if len(res) < 7 { //was node found?
                    res += "-1 -1 "
                }
                for k := i + 1; k < height; k++ {
                    if node[k][j] { //is there a node?
                        res += strconv.Itoa(j) + " " + strconv.Itoa(k) //end response
                        break
                    }
                }
                if len(res) < 11 { //was node found?
                    res += "-1 -1"
                }
                fmt.Println(res) //output response
            }
        }
    }

    // fmt.Fprintln(os.Stderr, "Debug messages...")

    //fmt.Println("0 0 1 0 0 1") // Three coordinates: a node, its right neighbor, its bottom neighbor
}

开发者ID:Renerte,项目名称:CodinGameSolutions,代码行数:60,代码来源:apu_init.go

示例5: main

func main() {
    B := new(big.Int).Exp(big.NewInt(2), big.NewInt(20), big.NewInt(0))

    p := new(big.Int)
    g := new(big.Int)
    h := new(big.Int)

    _, err := fmt.Sscan("13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084171", p)
    _, err = fmt.Sscan("11717829880366207009516117596335367088558084999998952205599979459063929499736583746670572176471460312928594829675428279466566527115212748467589894601965568", g)
    _, err = fmt.Sscan("3239475104050450443565264378728065788649097520952449527834792452971981976143292558073856937958553180532878928001494706097394108577585732452307673444020333", h)
    if err != nil {
        fmt.Println(err)
    }

    // Create a map that uses the calculations for x1's as keys
    hashTable := make(map[string]int64, B.Int64())

    var i int64
    for i = 0; i < B.Int64(); i++ {
        hashTable[computeX1(p, g, h, big.NewInt(i)).String()] = i
    }

    // Calculate the x0's and check if they are part of the hash table
    for i = 0; i < B.Int64(); i++ {
        x0Res := computeX0(p, g, B, big.NewInt(i))

        x1, found := hashTable[x0Res.String()]
        if found {
            x := B.Mul(B, big.NewInt(i))
            x.Add(x, big.NewInt(x1))
            fmt.Println("Solution:", x)
            return
        }
    }
}

开发者ID:MariaRigaki,项目名称:golang-stuff,代码行数:35,代码来源:week5.go

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