• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang fmt.Fscanf函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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


示例6: main

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

	s := bufio.NewScanner(in)
	s.Split(bufio.ScanLines)

	var n, c1, c2 int
	var line string
	for s.Scan() {
		if n, _ = strconv.Atoi(s.Text()); n == 0 {
			break
		}
		matrix := make([][]bool, n)
		for i := range matrix {
			matrix[i] = make([]bool, n)
		}
		for s.Scan() {
			if line = s.Text(); line == "0" {
				break
			}
			r := strings.NewReader(line)
			fmt.Fscanf(r, "%d", &c1)
			for {
				if _, err := fmt.Fscanf(r, "%d", &c2); err != nil {
					break
				}
				matrix[c1-1][c2-1], matrix[c2-1][c1-1] = true, true
			}
		}
		fmt.Fprintln(out, solve(matrix))
	}
}
开发者ID:codingsince1985,项目名称:UVa,代码行数:35,代码来源:315.go


示例7: main

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

	var n int
	for {
		if fmt.Fscanf(in, "%d%d", &t, &n); t == 0 && n == 0 {
			break
		}
		nums = make([]int, n)
		for i := range nums {
			fmt.Fscanf(in, "%d", &nums[i])
		}
		answers = nil
		backtracking(0, 0, nil)
		fmt.Fprintf(out, "Sums of %d:\n", t)
		if len(answers) == 0 {
			fmt.Fprintln(out, "NONE")
		} else {
			for _, answer := range answers {
				fmt.Fprintln(out, strings.Join(answer, "+"))
			}
		}
	}
}
开发者ID:codingsince1985,项目名称:UVa,代码行数:27,代码来源:574.go


示例8: main

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

	var kase, n int
	fmt.Fscanf(in, "%d", &kase)
	for kase > 0 {
		fmt.Fscanf(in, "\n%d", &n)
		n1 := make([]byte, n)
		n2 := make([]byte, n)
		for i := range n1 {
			fmt.Fscanf(in, "%d%d", &n1[i], &n2[i])
		}
		res := make([]byte, n)
		var carry bool
		for i := n - 1; i >= 0; i-- {
			sum := n1[i] + n2[i]
			if carry {
				sum++
			}
			carry = sum >= 10
			res[i] = sum % 10
		}
		for _, v := range res {
			fmt.Fprint(out, v)
		}
		fmt.Fprintln(out)
		kase--
	}
}
开发者ID:codingsince1985,项目名称:UVa,代码行数:32,代码来源:10013.go


示例9: main

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

	var n, q, height int
	fmt.Fscanf(in, "%d", &n)
	ladies := make([]int, n)
	for i := range ladies {
		fmt.Fscanf(in, "%d", &ladies[i])
	}
	fmt.Fscanf(in, "%d", &q)
	for q > 0 {
		fmt.Fscanf(in, "%d", &height)
		low, high := binarySearchLow(ladies, height), binarySearchHigh(ladies, height)
		if low != -1 {
			fmt.Fprint(out, low)
		} else {
			fmt.Fprint(out, "X")
		}
		if high != -1 {
			fmt.Fprintln(out, "", high)
		} else {
			fmt.Fprintln(out, " X")
		}
		q--
	}
}
开发者ID:codingsince1985,项目名称:UVa,代码行数:29,代码来源:10611.go


示例10: verifyOcSig

func verifyOcSig(reqHash []byte, ocID msg.OcID, sig string) bool {
	ocCredReader := strings.NewReader(ocID.String())
	var x, y, r, s big.Int
	n, err := fmt.Fscanf(ocCredReader, string(OC_ID_PREFIX)+"%x,%x", &x, &y)
	if err != nil {
		return false
	}
	n, err = ocCredReader.Read(make([]byte, 1))
	if n != 0 || err != io.EOF {
		return false
	}

	sigReader := strings.NewReader(sig)
	n, err = fmt.Fscanf(sigReader, "%x,%x", &r, &s)
	if err != nil {
		return false
	}
	n, err = sigReader.Read(make([]byte, 1))
	if n != 0 || err != io.EOF {
		return false
	}

	curve := elliptic.P256()
	pub := ecdsa.PublicKey{
		Curve: curve,
		X:     &x,
		Y:     &y,
	}
	return ecdsa.Verify(&pub, reqHash, &r, &s)
}
开发者ID:therob3000,项目名称:decloud,代码行数:30,代码来源:cred.go


示例11: main

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

	var kase, m, n int
	var fm, to string
	fmt.Fscanf(in, "%d\n", &kase)
	for kase > 0 {
		fmt.Fscanf(in, "\n%d%d", &m, &n)
		links = make(map[string][]string)
		for i := 0; i < m; i++ {
			fmt.Fscanf(in, "%s%s", &fm, &to)
			links[fm] = append(links[fm], to)
			links[to] = append(links[to], fm)
		}
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%s%s", &fm, &to)
			path := bfs(fm, to)
			for _, v := range path {
				fmt.Fprintf(out, "%c", v)
			}
			fmt.Fprintln(out)
		}
		if kase--; kase > 0 {
			fmt.Fprintln(out)
		}
	}
}
开发者ID:codingsince1985,项目名称:UVa,代码行数:30,代码来源:10009.go


示例12: parseFile

func parseFile(filename string) points {
	if filename == "" {
		log.Fatalf("No filename specified.")
	}

	// Open the file.
	fileReader, err := os.Open(filename)
	defer fileReader.Close()
	if err != nil {
		log.Fatalf("Error opening %s: %s.\n", filename, err)
	}

	var c uint
	n, err := fmt.Fscanf(fileReader, "%d\n", &c)
	if err != nil {
		log.Fatalf("Error scanning the first line. n: %d, err: %s.\n", n, err)
	}

	if c < 2 {
		log.Fatalf("Less than 2 points to compare. count: %d.\n", c)
	}

	p := make([]point, c)
	for i := 0; i < len(p); i++ {
		var x, y float64
		n, err := fmt.Fscanf(fileReader, "(%f,%f)\n", &x, &y)
		if err != nil {
			log.Fatalf("Error scanning line %d. n: %d, err: %s\n", i+1, n, err)
		}

		p[i] = point{x: x, y: y}
	}

	return p
}
开发者ID:dmikalova,项目名称:practice,代码行数:35,代码来源:main.go


示例13: main

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

	var n, s, n1, n2, kase int
	for {
		if fmt.Fscanf(in, "%d", &n); n == 0 {
			break
		}
		fmt.Fscanf(in, "%d", &s)
		adj = make([][]bool, n+1)
		for i := range adj {
			adj[i] = make([]bool, n+1)
		}
		for {
			if fmt.Fscanf(in, "%d%d", &n1, &n2); n1 == 0 && n2 == 0 {
				break
			}
			adj[n1][n2] = true
		}
		distance = make([]int, n+1)
		longest = 0
		lowest = math.MaxInt32
		dfs(s)
		kase++
		fmt.Fprintf(out, "Case %d: The longest path from %d has length %d, finishing at %d\n\n", kase, s, longest, lowest)
	}
}
开发者ID:codingsince1985,项目名称:UVa,代码行数:30,代码来源:10000.go


示例14: main

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

	var n int
	var x, y float64
	fmt.Fscanf(in, "%d", &n)
	fmt.Fprintln(out, "INTERSECTING LINES OUTPUT")
	for n > 0 {
		fmt.Fscanf(in, "%f%f", &x, &y)
		p1 := point{x, y}
		fmt.Fscanf(in, "%f%f", &x, &y)
		p2 := point{x, y}
		l1 := line{p1, p2}
		fmt.Fscanf(in, "%f%f", &x, &y)
		p1 = point{x, y}
		fmt.Fscanf(in, "%f%f", &x, &y)
		p2 = point{x, y}
		l2 := line{p1, p2}
		solve(l1, l2)
		n--
	}
	fmt.Fprintln(out, "END OF OUTPUT")
}
开发者ID:codingsince1985,项目名称:UVa,代码行数:26,代码来源:378.go


示例15: populateCreds

func (l *login) populateCreds(e *env) error {
	if l.credentials.email != "" && l.credentials.password != "" {
		return nil
	}

	fmt.Fprint(e.Out, "Email: ")
	fmt.Fscanf(e.In, "%s\n", &l.credentials.email)

	var (
		password string
		err      error
	)
	if e.In == os.Stdin {
		password, err = speakeasy.Ask("Password (will be hidden): ")
		if err != nil {
			return err
		}
	} else {
		// NOTE: only for testing
		fmt.Fscanf(e.In, "%s\n", &password)
	}

	if password != "" {
		l.credentials.password = password
	}
	return nil
}
开发者ID:WilliamRen,项目名称:parse-cli,代码行数:27,代码来源:login.go


示例16: main

func main() {
	// Read data.
	//r := bufio.NewReader(os.Stdin)

	// File operation.
	f, err := os.Open("in")
	if err != nil {
		return
	}
	defer f.Close()

	r := bufio.NewReader(f)
	w := bufio.NewWriter(os.Stdout)

	var n, val int
	fmt.Fscanf(r, "%d ", &n)

	var a []int
	for i := 0; i < n; i++ {
		fmt.Fscanf(r, " %d", &val)
		a = append(a, val)
	}

	// Output data.
	for _, val := range a {
		fmt.Fprintf(w, "%d ", val)
	}
	w.Flush()
}
开发者ID:ctliu3,项目名称:puzzles,代码行数:29,代码来源:template.go


示例17: main

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

	var cnt, tmp, set, kase, n1, n2 int
	for {
		matrix = make([][]bool, N+1)
		for i := range matrix {
			matrix[i] = make([]bool, N+1)
		}
		for i := 1; i < N; i++ {
			if _, err := fmt.Fscanf(in, "%d", &cnt); err != nil {
				return
			}
			for j := 0; j < cnt; j++ {
				fmt.Fscanf(in, "%d", &tmp)
				matrix[i][tmp] = true
				matrix[tmp][i] = true
			}
		}
		set++
		fmt.Fprintf(out, "Test Set #%d\n", set)
		fmt.Fscanf(in, "%d", &kase)
		for i := 0; i < kase; i++ {
			fmt.Fscanf(in, "%d%d", &n1, &n2)
			fmt.Fprintf(out, "%2d to %2d: %d\n", n1, n2, bfs(n1, n2))
		}
		fmt.Fprintln(out)
	}
}
开发者ID:codingsince1985,项目名称:UVa,代码行数:32,代码来源:567.go


示例18: main

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

	var shapes []shape
	var a, b, c, d, e, f float64
	var str string
	for {
		if fmt.Fscanf(in, "%s", &str); str == "*" {
			break
		}
		switch str {
		case "r":
			fmt.Fscanf(in, "%f%f%f%f", &a, &b, &c, &d)
			shapes = append(shapes, rectangle{point{a, b}, point{c, d}})
		case "c":
			fmt.Fscanf(in, "%f%f%f", &a, &b, &c)
			shapes = append(shapes, circle{point{a, b}, c})
		case "t":
			fmt.Fscanf(in, "%f%f%f%f%f%f", &a, &b, &c, &d, &e, &f)
			shapes = append(shapes, triangle{point{a, b}, point{c, d}, point{e, f}})
		}
	}

	count := 0
	for {
		if fmt.Fscanf(in, "%f%f", &a, &b); a == 9999.9 && b == 9999.9 {
			break
		}
		count++
		testIn(count, point{a, b}, shapes)
	}
}
开发者ID:codingsince1985,项目名称:UVa,代码行数:35,代码来源:478.go


示例19: main

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

	var kase, r, c, n int
	var grid [][]byte
	var line string
	fmt.Fscanf(in, "%d", &kase)
	for kase > 0 {
		fmt.Fscanf(in, "%d%d%d", &r, &c, &n)
		grid = make([][]byte, r)
		for j := range grid {
			grid[j] = make([]byte, c)
			fmt.Fscanf(in, "%s", &line)
			for k := range line {
				grid[j][k] = line[k]
			}
		}
		solve(grid, r, c, n)
		output(grid)
		if kase--; kase > 0 {
			fmt.Fprintln(out)
		}
	}
}
开发者ID:codingsince1985,项目名称:UVa,代码行数:27,代码来源:10443.go


示例20: main

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

	var n, n1, n2, kase int
	for {
		if _, err := fmt.Fscanf(in, "%d", &n); err != nil {
			break
		}
		var street [][2]int
		m = 0
		for n > 0 {
			fmt.Fscanf(in, "%d%d", &n1, &n2)
			street = append(street, [2]int{n1, n2})
			m = max(m, max(n1, n2))
			n--
		}
		fmt.Fprintf(out, "matrix for city %d\n", kase)
		kase++
		for _, vi := range solve(street) {
			fmt.Fprintln(out, strings.Join(vi, " "))
		}
	}
}
开发者ID:codingsince1985,项目名称:UVa,代码行数:26,代码来源:125.go



注:本文中的fmt.Fscanf函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang fmt.Fscanln函数代码示例发布时间:2022-05-24
下一篇:
Golang fmt.Fscan函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap