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

Golang fmt.Fscanln函数代码示例

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

本文整理汇总了Golang中fmt.Fscanln函数的典型用法代码示例。如果您正苦于以下问题:Golang Fscanln函数的具体用法?Golang Fscanln怎么用?Golang Fscanln使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Fscanln函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: main

func main() {
	var num1 int
	var num2 float32
	var s string

	file1, _ := os.Open("hello1.txt")          // hello1.txt 파일 열기
	defer file1.Close()                        // main 함수가 끝나기 직전에 파일을 닫음
	n, _ := fmt.Fscan(file1, &num1, &num2, &s) // 파일을 읽은 뒤 공백, 개행 문자로
	// 구분된 문자열에서 입력을 받음
	fmt.Println("입력 개수:", n)   // 입력 개수: 3
	fmt.Println(num1, num2, s) // 1 1.1 Hello

	file2, _ := os.Open("hello2.txt")    // hello2.txt 파일 열기
	defer file2.Close()                  // main 함수가 끝나기 직전에 파일을 닫음
	fmt.Fscanln(file2, &num1, &num2, &s) // 파일을 읽은 뒤 공백으로
	// 구분된 문자열에서 입력을 받음
	fmt.Println("입력 개수:", n)   // 입력 개수: 3
	fmt.Println(num1, num2, s) // 1 1.1 Hello

	file3, _ := os.Open("hello3.txt")               // hello3.txt 파일 열기
	defer file3.Close()                             // main 함수가 끝나기 직전에 파일을 닫음
	fmt.Fscanf(file3, "%d,%f,%s", &num1, &num2, &s) // 파일을 읽은 뒤 문자열에서
	// 형식을 지정하여 입력을 받음
	fmt.Println("입력 개수:", n)   // 입력 개수: 3
	fmt.Println(num1, num2, s) // 1 1.1 Hello
}
开发者ID:jemoonkim,项目名称:golangbook,代码行数:26,代码来源:Fcan.go


示例17: main

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

	var n int
	var ch byte
	for {
		if fmt.Fscanf(in, "%d", &n); n == 0 {
			break
		}
		nums := make([]int, n)
		max := 0
		for n > 0 {
			num := 0
			for i := 1; i <= 25; i++ {
				if fmt.Fscanf(in, "%c", &ch); ch == 'X' {
					num++
				}
			}
			fmt.Fscanln(in)
			if num > max {
				max = num
			}
			nums[n-1] = num
			n--
		}
		total := 0
		for _, v := range nums {
			total += max - v
		}
		fmt.Fprintln(out, total)
	}
}
开发者ID:codingsince1985,项目名称:UVa,代码行数:35,代码来源:414.go


示例18: run

func run(r io.Reader, w io.Writer) {
	var start, end int
	fmt.Fscanln(r, &start)
	fmt.Fscanln(r, &end)
	maxValue := 0
	for i := start; i < end; i++ {
		for j := i + 1; j <= end; j++ {
			v := i ^ j
			if maxValue < v {
				maxValue = v
			}
		}
	}

	fmt.Fprintln(w, maxValue)
}
开发者ID:snnn,项目名称:onlinejudge,代码行数:16,代码来源:main.go


示例19: meminfo

// There must be a better way if we call this a lot..
func meminfo() (total, free, buffers, cached ByteSize) {
	fd, err := os.Open("/proc/meminfo")
	defer fd.Close()
	if err != nil {
		panic(err)
	}

	mapping := map[string]*ByteSize{
		"MemTotal": &total,
		"MemFree":  &free,
		"Buffers":  &buffers,
		"Cached":   &cached,
	}

	var name, unit string
	var value int64

	for {
		n, err := fmt.Fscanln(fd, &name, &value, &unit)
		if err == io.EOF {
			break
		}
		if n < 2 {
			continue
		}
		what, present := mapping[name[:len(name)-1]]
		if present {
			*what = ByteSize(value) * kiB
		}
	}

	return
}
开发者ID:pwaller,项目名称:go-memhelper,代码行数:34,代码来源:memhelper.go


示例20: main

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

	var n int
	var line string
	first := true
	fmt.Fscanf(in, "%d", &n)
	for n > 0 {
		n--
		if first {
			first = false
		} else {
			fmt.Fprintln(out)
		}
		fmt.Fscanln(in)
		fmt.Fscanf(in, "%s", &line)
		ks := factors(len(line))
		for _, k := range ks {
			if periodic(line, k) {
				fmt.Fprintln(out, k)
				break
			}
		}
	}
}
开发者ID:codingsince1985,项目名称:UVa,代码行数:28,代码来源:455.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang fmt.Print函数代码示例发布时间:2022-05-24
下一篇:
Golang fmt.Fscanf函数代码示例发布时间: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