當前位置: 首頁>>代碼示例>>Golang>>正文


Golang fmt.Fscanf函數代碼示例

本文整理匯總了Golang中fmt.Fscanf函數的典型用法代碼示例。如果您正苦於以下問題:Golang Fscanf函數的具體用法?Golang Fscanf怎麽用?Golang Fscanf使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Fscanf函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的fmt.Fscanf函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。