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


Golang fmt.Fscanln函數代碼示例

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


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

示例1: readPlaces

func readPlaces() ([]node, int) {
	f, err := os.Open("agraph")
	if err != nil {
		panic(err)
	}
	defer f.Close()

	var numNodes int
	if _, err := fmt.Fscanln(f, &numNodes); err != nil {
		panic(err)
	}

	nodes := make([]node, numNodes)
	for i := range nodes {
		nodes[i].neighbours = make([]route, 0, numNodes/2)
	}

	for {
		var node int32
		var r route

		switch _, err := fmt.Fscanln(f, &node, &r.to, &r.cost); {
		case err == io.EOF:
			return nodes, numNodes
		case err != nil:
			panic(err)
		}
		nodes[node].neighbours = append(nodes[node].neighbours, r)
	}
}
開發者ID:Abbath,項目名稱:LPATHBench,代碼行數:30,代碼來源:go.go

示例2: main

func main() {
	in := bufio.NewReader(os.Stdin)

	var n int
	fmt.Fscanln(in, &n)

	cnt := 0
	val := 0

	for i := 0; i < n; i++ {
		var k int
		fmt.Fscanln(in, &k)

		if cnt == 0 {
			cnt = 1
			val = k
		} else if val == k {
			cnt++
		} else {
			cnt--
		}
	}

	fmt.Println(val)
}
開發者ID:esix,項目名稱:competitive-programming,代碼行數:25,代碼來源:solution.go

示例3: main

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

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

	sums := make([]int, n+1)

	sum := 0
	for i := 1; i <= n; i++ {
		var a int
		fmt.Fscanln(bi, &a)
		sum += a
		sums[i] = sum
	}

	fmt.Fscanln(bi, &q)
	for i := 0; i < q; i++ {
		var s, e int
		fmt.Fscanln(bi, &s, &e)
		fmt.Fprintln(bo, sums[e]-sums[s-1])
	}
	bo.Flush()
}
開發者ID:esix,項目名稱:competitive-programming,代碼行數:25,代碼來源:solution.go

示例4: setflag

func setflag(c io.ReadWriteCloser) {
	defer c.Close()

	var flag_id string
	fmt.Fprintln(c, "room_id: ")
	_, err := fmt.Fscanln(c, &flag_id)
	if err != nil {
		return
	}
	var cookie string
	fmt.Fprintln(c, "auth_token: ")
	_, err = fmt.Fscanln(c, &cookie)
	if err != nil {
		return
	}
	var flag string
	fmt.Fprintln(c, "flag: ")
	_, err = fmt.Fscanln(c, &flag)
	if err != nil {
		return
	}

	if db.Set(flag_id, []string{cookie, flag}) {
		fmt.Fprintln(c, "set_flag flag_set")
		log.Println("setflag: flag set")
	} else if cookie == db.Get(flag_id)[0] {
		db.Update(flag_id, []string{cookie, flag})
		fmt.Fprintln(c, "setflag: flag_updated")
		log.Println("setflag: flag updated")
	} else {
		fmt.Fprintln(c, "setflag: flag_update_auth_fail")
		log.Println("setflag: auth fail")
	}
}
開發者ID:AdaLovelance,項目名稱:ictf-framework,代碼行數:34,代碼來源:tattletale.go

示例5: main

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

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

	ls := make(Lectures, n)

	for i := 0; i < n; i++ {
		fmt.Fscanln(bi, &ls[i].S, &ls[i].E)
	}

	sort.Sort(ls)

	res := 0
	min_time := 0

	for _, l := range ls {
		if l.S > min_time {
			min_time = l.E
			res++
		}
	}

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

示例6: main

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

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

	best_n := 1
	var best_d int64

	fmt.Fscanln(bi, &prev)
	for i := 1; i < n; i++ {
		var v int
		fmt.Fscanln(bi, &v)
		d := abs(int64(v) - int64(prev))

		if d >= best_d {
			best_n = i
			best_d = d
		}

		prev = v
	}

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

示例7: getflag

func getflag(c io.ReadWriteCloser) {
	defer c.Close()
	var flag_id string
	fmt.Fprintln(c, "flag_id: ")
	_, err := fmt.Fscanln(c, &flag_id)
	if err != nil {
		return
	}
	var cookie string
	fmt.Fprintln(c, "token_id: ")
	_, err = fmt.Fscanln(c, &cookie)
	if err != nil {
		return
	}
	entry := db.Get(flag_id)
	if entry == nil {
		fmt.Fprintln(c, "flagval: no_entry_exists")
		log.Println("getflag: request for non-existant entry")
	} else if cookie == entry[0] {
		fmt.Fprintln(c, "flagval:", entry[1])
		log.Println("getflag: got")
	} else {
		fmt.Fprintln(c, "flagval: getflag_auth_fail")
		log.Println("getflag: auth fail")
	}
	return
}
開發者ID:AdaLovelance,項目名稱:ictf-framework,代碼行數:27,代碼來源:tattletale.go

示例8: passDetails

func passDetails(
	binary_path string,
	begin_time time.Time,
	duration time.Duration,
	latitude_degrees,
	longitude_degrees,
	elevation_metres float64,
	tle string,
	resolution_seconds float64) ([]SatPoint, error) {

	begin_timestamp := 1e-9 * float64(begin_time.UnixNano())

	c := exec.Command("python", binary_path)
	in_pipe, err := c.StdinPipe()
	if err != nil {
		return nil, err
	}
	defer in_pipe.Close()
	out_pipe, err := c.StdoutPipe()
	if err != nil {
		return nil, err
	}
	defer out_pipe.Close()
	if err := c.Start(); err != nil {
		return nil, err
	}
	defer c.Wait()

	fmt.Fprintf(in_pipe, "%f\n%f\n%f\n%f\n%f\n%s\n%f\n",
		begin_timestamp,
		duration.Seconds(),
		latitude_degrees,
		longitude_degrees,
		elevation_metres,
		tle,
		resolution_seconds)
	in_pipe.Close()

	var n int
	_, err = fmt.Fscanln(out_pipe, &n)
	if err != nil {
		return nil, err
	}

	r := make([]SatPoint, n)
	for i := 0; i < n; i++ {
		p := &r[i]
		fmt.Fscanln(out_pipe,
			&p.Timestamp,
			&p.AzimuthDegrees,
			&p.AltitudeDegrees,
			&p.Range,
			&p.RangeVelocity,
			&p.LatitudeDegrees,
			&p.LongitudeDegrees,
			&p.Elevation,
			&p.IsEclipsed)
	}
	return r, nil
}
開發者ID:tstranex,項目名稱:carpcomm,代碼行數:60,代碼來源:pass_details.go

示例9: predict

func predict(
	predict_binary_path string,
	begin_time time.Time,
	duration time.Duration,
	latitude_degrees,
	longitude_degrees,
	elevation_metres,
	min_altitude_degrees,
	min_azimuth_degrees,
	max_azimuth_degrees float64,
	tle string) ([]Prediction, error) {

	begin_timestamp := 1e-9 * float64(begin_time.UnixNano())

	c := exec.Command("python", predict_binary_path)
	in_pipe, err := c.StdinPipe()
	if err != nil {
		return nil, err
	}
	defer in_pipe.Close()
	out_pipe, err := c.StdoutPipe()
	if err != nil {
		return nil, err
	}
	defer out_pipe.Close()
	if err := c.Start(); err != nil {
		return nil, err
	}
	defer c.Wait()

	fmt.Fprintf(in_pipe, "%f\n%f\n%f\n%f\n%f\n%f\n%f\n%f\n%s\n",
		begin_timestamp,
		duration.Seconds(),
		latitude_degrees,
		longitude_degrees,
		elevation_metres,
		min_altitude_degrees,
		min_azimuth_degrees,
		max_azimuth_degrees,
		tle)
	in_pipe.Close()

	var n int
	_, err = fmt.Fscanln(out_pipe, &n)
	if err != nil {
		return nil, err
	}

	r := make([]Prediction, n)
	for i := 0; i < n; i++ {
		p := &r[i]
		fmt.Fscanln(out_pipe,
			&p.StartTimestamp,
			&p.EndTimestamp,
			&p.StartAzimuthDegrees,
			&p.EndAzimuthDegrees,
			&p.MaxAltitudeDegrees)
	}
	return r, nil
}
開發者ID:tstranex,項目名稱:carpcomm,代碼行數:60,代碼來源:predict.go

示例10: CreateConfig

// CreateConfig creates a configuration file and saves it to the file at the given path.
func CreateConfig(path string) error {
	config, _ := LoadConfig(path)
	var emailDef, passwordDef, accountDef, hostDef string
	if config != nil {
		yn := PromptConfirmation("Found existing configuration file %v, overwrite? (y/N): ", path)
		if yn != "y" {
			PrintSuccess("Exiting")
			return nil
		}
		emailDef = fmt.Sprintf(" (%v)", config.Email)
		accountDef = fmt.Sprintf(" (%v)", config.Account)
		passwordDef = " (leave blank to leave unchanged)"
		if config.LoginHost == "" {
			config.LoginHost = "my.rightscale.com"
		}
		hostDef = fmt.Sprintf(" (%v)", config.LoginHost)
	} else {
		config = &ClientConfig{}
	}

	fmt.Fprintf(out, "Account id%v: ", accountDef)
	var newAccount string
	fmt.Fscanln(in, &newAccount)
	if newAccount != "" {
		a, err := strconv.Atoi(newAccount)
		if err != nil {
			return fmt.Errorf("Account ID must be an integer, got '%s'.", newAccount)
		}
		config.Account = a
	}

	fmt.Fprintf(out, "Login email%v: ", emailDef)
	var newEmail string
	fmt.Fscanln(in, &newEmail)
	if newEmail != "" {
		config.Email = newEmail
	}

	fmt.Fprintf(out, "Login password%v: ", passwordDef)
	var newPassword string
	fmt.Fscanln(in, &newPassword)
	if newPassword != "" {
		config.Password = newPassword
	}

	fmt.Fprintf(out, "API Login host%v: ", hostDef)
	var newLoginHost string
	fmt.Fscanln(in, &newLoginHost)
	if newLoginHost != "" {
		config.LoginHost = newLoginHost
	}

	err := config.Save(path)
	if err != nil {
		return fmt.Errorf("Failed to save config: %s", err)
	}

	return nil
}
開發者ID:lopaka,項目名稱:rsc,代碼行數:60,代碼來源:config.go

示例11: load

func load(stdin io.Reader) {
	var n int
	fmt.Fscanln(stdin, &n)
	var s string
	fmt.Fscanln(stdin, &s)
	s = s[0:n] // just in case string is overlong
	var k int
	fmt.Fscan(stdin, &k)
	fmt.Println(solve(s, k))
}
開發者ID:cohadar,項目名稱:hackerrank,代碼行數:10,代碼來源:ceasar-cipher.go

示例12: main

func main() {
	if len(os.Args) < 2 {
		fmt.Println("Arquivo de entrada não encontrado")
		os.Exit(1)
	}

	file, err := os.Open(os.Args[1])
	if err != nil {
		fmt.Println("Falha de leitura")
		os.Exit(1)
	}

	var input string
	_, err = fmt.Fscanln(file, &input)
	if err != nil {
		fmt.Println("Arquivo Vazio")
		fmt.Println(err.Error())
		os.Exit(1)
	}
	start := time.Now()
	for true {
		read, err := fmt.Fscanln(file, &input)
		values := strings.Split(input, ",")
		if read == 0 || err != nil {
			break
		}

		if len(values) != 4 {
			fmt.Println("Inputs errados")
			fmt.Println(values)
			os.Exit(1)
		}
		politica, ok := policies.Politicas[values[1]]
		seed, err := strconv.Atoi(values[3])
		if !ok {
			if values[1] == "reinforcement_learning" {
				rand.Seed(int64(seed))
				policies.TrainReinf()
				politica = policies.Politicas["reinforcement_learning"]
			} else {
				fmt.Println("Política Invalida")
				os.Exit(1)
			}

		}
		games, err := strconv.Atoi(values[0])
		pieces, err := strconv.Atoi(values[2])

		fmt.Println(tetris.Play_series(int64(seed), pieces, games, politica))
	}
	elapsed := time.Since(start)
	fmt.Println("Everything took", elapsed)
	os.Exit(0)
}
開發者ID:hbejgel,項目名稱:projeto_final,代碼行數:54,代碼來源:main.go

示例13: load

func load(stdin io.Reader) {
	var n int
	fmt.Fscanln(stdin, &n)
	M := make([][]int, n)
	for y := 0; y < len(M); y++ {
		M[y] = make([]int, n)
		s := make([]byte, n)
		fmt.Fscanln(stdin, &s)
		for x := 0; x < len(M[y]); x++ {
			M[y][x] = int(s[x] - '0')
		}
	}
	solve(M)
}
開發者ID:cohadar,項目名稱:hackerrank,代碼行數:14,代碼來源:cavity-map.go

示例14: getArgs

func getArgs(r io.Reader) []string {
	numArgs := 0
	_, err := fmt.Fscanln(r, &numArgs)

	timeArgs := []string{}
	for {
		timeArg := ""
		_, err = fmt.Fscanln(r, &timeArg)
		if err == io.EOF {
			break
		}
		timeArgs = append(timeArgs, timeArg)
	}
	return timeArgs
}
開發者ID:nii236,項目名稱:hackerrank,代碼行數:15,代碼來源:main.go

示例15: main

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

	var kase int
	var line string
	first := true
	fmt.Fscanf(in, "%d", &kase)
	for kase > 0 {
		if first {
			fmt.Fscanln(in)
			first = false
		} else {
			fmt.Fprintln(out)
		}
		var lines []string
		for {
			if _, err := fmt.Fscanf(in, "%s", &line); err != nil {
				break
			}
			lines = append(lines, line)
		}
		fmt.Fprintln(out, solve(lines))
		kase--
	}
}
開發者ID:codingsince1985,項目名稱:UVa,代碼行數:28,代碼來源:10033.go


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