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


Golang fmt.Fscan函數代碼示例

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


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

示例6: constructKeys

func (self *node) constructKeys(file *os.File, keyCnt int, typ int) {
	var key common.CellValue
	var intval common.IntVal
	var fltval common.FltVal
	var strval common.StrVal
	for i := 0; i < keyCnt; i++ {
		switch typ {
		case common.IntCol:
			fmt.Fscan(file, &intval)
			key = intval
		case common.FltCol:
			fmt.Fscan(file, &fltval)
			key = fltval
		case common.StrCol:
			fmt.Fscan(file, &strval)
			key = strval
		}
		self.keys = append(self.keys, key)
	}
	var recordId int64
	if self.isLeaf() {
		for i := 0; i < keyCnt; i++ {
			fmt.Fscan(file, &recordId)
			self.recordIds = append(self.recordIds, recordId)
		}
	}
}
開發者ID:aquarhead,項目名稱:minisql_dbms,代碼行數:27,代碼來源:file_manipulate.go

示例7: grade

func grade(in io.Reader) []byte {
	var n, m int
	fmt.Fscanln(in, &n, &m)

	records := []record{}

	var overallavg float64
	for i := 0; i < n; i++ {
		r := record{}
		fmt.Fscan(in, &r.name)
		for j := 0; j < m; j++ {
			var tmp float64
			fmt.Fscan(in, &tmp)
			r.grades = append(r.grades, tmp)
			r.avg += tmp
		}
		r.avg /= float64(len(r.grades))
		overallavg += r.avg
		records = append(records, r)
	}
	overallavg /= float64(n)

	o := new(bytes.Buffer)
	fmt.Fprintf(o, "%.2f\n", overallavg)
	for _, r := range records {
		fmt.Fprintf(o, "%s %.2f\n", r.name, r.avg)
	}
	return o.Bytes()
}
開發者ID:kranthikumar,項目名稱:Weekly-Problems,代碼行數:29,代碼來源:student_management.go

示例8: main

func main() {
	h := &IntHeap{}
	heap.Init(h)
	dict := map[int]bool{}
	var inputSize int
	var diff int
	io := bufio.NewReader(os.Stdin)

	fmt.Fscan(io, &inputSize)
	fmt.Fscan(io, &diff)
	for i := 0; i < inputSize; i++ {
		var number int
		fmt.Fscan(io, &number)
		heap.Push(h, number)
		dict[number] = true
	}
	pairCount := 0
	for i := 0; h.Len() > 0; i++ {
		curr := heap.Pop(h).(int)
		_, ok := dict[curr+diff]
		if ok {
			pairCount++
		}
	}
	fmt.Println(pairCount)
}
開發者ID:knd,項目名稱:hackerrank,代碼行數:26,代碼來源:Pairs.go

示例9: main

func main() {
	bi := bufio.NewReader(os.Stdin)
	bo := bufio.NewWriter(os.Stdout)
	defer bo.Flush()

	var n, m int
	fmt.Fscanln(bi, &n, &m)

	g := make([]int, n)
	for i := range g {
		fmt.Fscan(bi, &g[i])
	}

	b := make([]int, m)
	for i := range b {
		fmt.Fscan(bi, &b[i])
	}

	sort.Ints(g)
	sort.Ints(b)

	res := sum(g) // no one takes

	for k := 1; k <= min(len(b), len(g)); k++ {
		new_res := sum(g[:len(g)-k]) + sum(b[:len(b)-k])*k
		if new_res < res {
			res = new_res
		}
	}

	fmt.Fprintln(bo, res)
}
開發者ID:esix,項目名稱:competitive-programming,代碼行數:32,代碼來源:solution.go

示例10: main

func main() {
	var inputSize int
	io := bufio.NewReader(os.Stdin)
	fmt.Fscan(io, &inputSize)
	var maxDiff int
	var firstStr string
	var secondStr string

	for i := 0; i < inputSize; i++ {
		fmt.Fscan(io, &maxDiff)
		fmt.Fscan(io, &firstStr)
		fmt.Fscan(io, &secondStr)
		best := 0
		for j := 0; j < len(firstStr); j++ {
			best1 := getBest(firstStr, secondStr, 0, j, maxDiff)
			best2 := getBest(firstStr, secondStr, j, 0, maxDiff)
			if best1 > best && best1 >= best2 {
				best = best1
			}
			if best2 > best && best2 >= best1 {
				best = best2
			}
		}
		fmt.Println(best)
	}

}
開發者ID:knd,項目名稱:hackerrank,代碼行數:27,代碼來源:SubstringDiff.go

示例11: readCages

func (s *Sudoku) readCages(f *os.File) error {
	var ncages int
	fmt.Fscan(f, &ncages)

	s.Cages = make([]*Cage, ncages)

	for i := 0; i < ncages; i++ {
		var sum int8
		var ncells int
		fmt.Fscan(f, &sum, &ncells)

		cage := &Cage{
			Sum:   sum,
			Cells: make([]*Cell, ncells),
		}

		var row, col int8
		for j := 0; j < ncells; j++ {
			fmt.Fscanf(f, "%d,%d", &col, &row)
			cage.Cells[j] = &Cell{
				Row: row,
				Col: col,
			}
		}

		s.Cages[i] = cage
	}

	return nil
}
開發者ID:ernestoalejo,項目名稱:sudokuk,代碼行數:30,代碼來源:sudoku.go

示例12: main

func main() {
	var userURL string
	stdin := bufio.NewReader(os.Stdin)

	fmt.Println("Enter a valid URL:")
	_, err := fmt.Fscan(stdin, &userURL)
	stdin.ReadString('\n')

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

	for len(userURL) == 0 {
		fmt.Println("[!] URL can't be empty!")
		_, err := fmt.Fscan(stdin, &userURL)
		stdin.ReadString('\n')
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
	}

	response := url.GetPageSource(userURL)
	videoUser := url.GetVideoDetails(response)
	videoNumber := videoUser.GetUserAnswer()
	url.DownloadFile(videoUser.Links[videoNumber-1].Type, videoUser)
}
開發者ID:pluralism,項目名稱:bliptv-downloader,代碼行數:28,代碼來源:main.go

示例13: getEventId

func getEventId(sysCall string) uint32 {
	f, err := os.Open(TracePath + EventPath + "/" + sysCall + "/format")
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()
	var token string
	for {
		_, err = fmt.Fscan(f, &token)
		if err != nil {
			log.Fatal(err)
		}
		if token == "ID:" {
			_, err = fmt.Fscan(f, &token)
			if err != nil {
				log.Fatal(err)
			}
			v, err := strconv.Atoi(token)
			if err != nil {
				log.Fatal(err)
			}
			return uint32(v)
		}
	}
}
開發者ID:taysom,項目名稱:va,代碼行數:25,代碼來源:ktop.go

示例14: load

func load(stdin io.Reader) {
	var t int
	fmt.Fscan(stdin, &t)
	for i := 0; i < t; i++ {
		var n, c, m int
		fmt.Fscan(stdin, &n, &c, &m)
		fmt.Println(solve(n, c, m))
	}
}
開發者ID:cohadar,項目名稱:hackerrank,代碼行數:9,代碼來源:chocolate-feast.go

示例15: load

func load(stdin io.Reader) {
	var t int
	fmt.Fscan(stdin, &t)
	for i := 0; i < t; i++ {
		var a, b int
		fmt.Fscan(stdin, &a, &b)
		fmt.Println(a + b)
	}
}
開發者ID:cohadar,項目名稱:hackerrank,代碼行數:9,代碼來源:solve-me-second.go


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