当前位置: 首页>>代码示例>>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;未经允许,请勿转载。