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


Golang fmt.Scanf函數代碼示例

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


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

示例1: main

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &arr[i])
	}
	var i, j, l, cnt int
	arrLen := n
	for cnt = 0; ; cnt++ {
		j = 0
		for i, l = 1, arrLen; i < l; i++ {
			if arr[i-1] >= arr[i] {
				j++
				arr[j] = arr[i]
			}
		}
		if i == j+1 {
			fmt.Println(cnt)
			break
		}
		arrLen = j + 1
	}

}
開發者ID:yaru22,項目名稱:problem-solving,代碼行數:25,代碼來源:poisonous_plants.go

示例2: main

func main() {
	var x, y int

	fmt.Scanf("%d", &N)
	P = make(Ps, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d %d", &x, &y)
		P[i] = NewPoint(i, x, y)
		T[i].l = NIL
		T[i].r = NIL
		T[i].p = NIL
	}
	np = 0
	root := makeKDTree(0, N, 0)

	log.Println(P)
	log.Println(T)
	var q int
	fmt.Scanf("%d", &q)
	var sx, tx, sy, ty int
	for i := 0; i < q; i++ {
		fmt.Scanf("%d %d %d %d", &sx, &tx, &sy, &ty)
		ans := lib.NewVector(N)
		log.Println(ans)
		find(root, sx, tx, sy, ty, 0, ans)
		for j := 0; j < ans.Size(); j++ {
			an := ans.V[j]
			ap := an.(Point)
			ap.disp()
		}
	}
}
開發者ID:iyoo14,項目名稱:goalgo,代碼行數:32,代碼來源:kdtree.go

示例3: main

func main() {
	var T int
	fmt.Scanf("%d", &T)
	for t := 0; t < T; t++ {
		var N int
		fmt.Scanf("%d", &N)
		var no5, no3 = 0, 0
		for i := N / 3; i >= 0; i-- {
			if (N-3*i)%5 == 0 {
				no3 = i
				no5 = (N - 3*i) / 5
				break
			}
		}
		if no3 == 0 && no5 == 0 {
			fmt.Println("-1")
		} else {
			for i := 0; i < 3*no3; i++ {
				fmt.Print("5")
			}
			for i := 0; i < 5*no5; i++ {
				fmt.Print("3")
			}
			fmt.Println()
		}
	}
}
開發者ID:mohan08p,項目名稱:Competitive_Programming,代碼行數:27,代碼來源:solution.go

示例4: SetChannelState

//SetChannelState sets the Channel inside the State
func SetChannelState(dg *discordgo.Session) {
	State.InsertMode = false

	guild := State.Guild
	d := color.New(color.FgYellow, color.Bold)
	d.Printf("Select a Channel:\n")
	for key, channel := range guild.Channels {
		if channel.Type == "text" {
			fmt.Printf("%d:%s\n", key, channel.Name)
		}
	}

	var response int
	fmt.Scanf("%d\n", &response)
	for guild.Channels[response].Type != "text" {
		Error := color.New(color.FgRed, color.Bold)
		Error.Printf("That's a voice channel, you know this is a CLI right?\n")
		d.Printf("Select a Channel:\n")
		fmt.Scanf("%d\n", &response)
	}

	State.Channel = guild.Channels[response]

	Clear()

	State.InsertMode = true
}
開發者ID:iopred,項目名稱:discord-cli,代碼行數:28,代碼來源:init.go

示例5: main

func main() {
	var n int64
	var ans, m, t, i int64
	var a [200]int64
	fmt.Scanf("%v\n", &n)
	for i = 1; i <= n; i++ {
		fmt.Scanf("%v", &a[i])
	}

	t = 1
	ans = 1
	for a[t] == 0 {
		t = t + 1
		if t == n+2 {
			ans = 0
			break
		}
	}
	m = 0
	for i = t; i <= n; i++ {
		if a[i] == 1 {
			ans = ans * (m + 1)
			m = 0
		} else {
			m = m + 1
		}
	}
	fmt.Println(ans)
}
開發者ID:BanSheeGun,項目名稱:Gun,代碼行數:29,代碼來源:B.go

示例6: main

func main() {

	var t, n int
	var result int
	var num int

	fmt.Scanf("%d", &t)

	for ; t != 0; t-- {
		fmt.Scanf("%d", &n)
		for i := 0; i < n; i++ {
			for j := 0; j <= i; j++ {

				fmt.Scanf("%d", &num)
				matrix[i][j] = num

			}
		}

		result = bottomUp(n - 1)

		fmt.Println(result)

	}
	//Enter your code here. Read input from STDIN. Print output to STDOUT
}
開發者ID:telmojsneves,項目名稱:hackerrank,代碼行數:26,代碼來源:euler_067.go

示例7: main

func main() {

	var (
		myList []int
		choice int
		num    int
	)

	fmt.Println("Enter a list of numbers to be sorted, after each input you ll be prompted with a choice {continue(1)/quit(0)}")

	for {
		fmt.Println("Enter a number")
		if _, err := fmt.Scanf("%d", &num); err != nil {
			log.Fatalln(err)
		}
		myList = append(myList, num)
		fmt.Println("Do you wish to continue or quit")
		if _, err := fmt.Scanf("%d", &choice); err == nil {
			if choice == 1 {
				continue
			} else {
				break
			}
		}
	}

	insertionSort(myList)

}
開發者ID:rhatdan,項目名稱:Algorithms,代碼行數:29,代碼來源:insertionSort.go

示例8: main

func main() {
	secret := rand.Int() % 500

	oldguess := secret
	var guess int

	fmt.Printf("Enter your guess: ")
	fmt.Scanf("%d", &guess)
	tries := 1
	for guess != secret {
		if guess < secret {
			fmt.Println("Too low!")
		} else if guess > secret {
			fmt.Println("Too high!")
		}
		fmt.Printf("Enter your guess: ")
		fmt.Scanf("%d", &guess)

		if guess != oldguess {
			tries++
		}
		oldguess = guess
	}
	fmt.Printf("That's correct, the number was %v\n", secret)
	fmt.Printf("You used %v tries", tries)
}
開發者ID:roessland,項目名稱:adriannproglems,代碼行數:26,代碼來源:elementary9-guess.go

示例9: main

func main() {

	var n int
	fmt.Scanf("%d\n", &n)
	re := regexp.MustCompile("(R\\d+C\\d+)|(([A-Z]+)(\\d+))")

	for i := 0; i < n; i++ {

		var k string
		fmt.Scanf("%s\n", &k)

		ss := re.FindStringSubmatch(k)

		if len(ss[1]) > 0 {
			var a, b int
			fmt.Sscanf(ss[1], "R%dC%d", &a, &b)
			fmt.Printf("%s%d\n", itos(b), a)
		}

		if len(ss[2]) > 0 {
			a := ss[3]
			var b int
			fmt.Sscanf(ss[4], "%d", &b)
			fmt.Printf("R%dC%d\n", b, stoi(a))
		}
	}

}
開發者ID:giter,項目名稱:codeforces-ans,代碼行數:28,代碼來源:1B.go

示例10: main

func main() {
	var nrows, ncols, percent int

	flag.Parse()

	fmt.Scanf("%d%d", &nrows, &ncols)

	if !*is_bench {
		for i := 0; i < nrows; i++ {
			for j := 0; j < ncols; j++ {
				fmt.Scanf("%d", &matrix[i][j])
			}
		}
	}

	fmt.Scanf("%d", &percent)

	thresh(nrows, ncols, percent)

	if !*is_bench {
		for i := 0; i < nrows; i++ {
			for j := 0; j < ncols; j++ {
				fmt.Printf("%d ", mask[i][j])
			}
			fmt.Printf("\n")
		}
		fmt.Printf("\n")
	}
}
開發者ID:scottgw,項目名稱:concurrent-languages,代碼行數:29,代碼來源:main.go

示例11: Login

func Login(args []string, opts map[string]interface{}) {
	user := &userInfo{CurDir: "/"}
	if len(args) == 3 {
		user.Bucket = args[0]
		user.Username = args[1]
		user.Password = args[2]
	} else {
		fmt.Printf("ServiceName: ")
		fmt.Scanf("%s\n", &user.Bucket)
		fmt.Printf("Operator: ")
		fmt.Scanf("%s\n", &user.Username)
		fmt.Printf("Password: ")
		b, err := gopass.GetPasswdMasked()
		if err == nil {
			user.Password = string(b)
		}
	}

	if _, err := NewFsDriver(user.Bucket, user.Username,
		user.Password, user.CurDir, 10, nil); err != nil {
		fmt.Fprintf(os.Stderr, "failed to log in. %v\n", err)
		os.Exit(-1)
	}

	// save
	conf.UpdateUserInfo(user)
	conf.Save(confname)
}
開發者ID:GeorgeChan,項目名稱:upx,代碼行數:28,代碼來源:commands.go

示例12: main

func main() {
	var p, q, l, r int
	fmt.Scanf("%d %d %d %d\n", &p, &q, &l, &r)
	a := make([]int, p)
	b := make([]int, p)
	c := make([]int, q)
	d := make([]int, q)
	for i := 0; i < p; i++ {
		fmt.Scanf("%d %d\n", &a[i], &b[i])
	}

	for i := 0; i < q; i++ {
		fmt.Scanf("%d %d\n", &c[i], &d[i])
	}

	ans := 0
	for t := l; t <= r; t++ {
		f := false
		for i := 0; (i < p) && !(f); i++ {
			for j := 0; (j < q) && !(f); j++ {
				f = (c[j]+t <= b[i]) && (d[j]+t >= a[i])
			}
		}

		if f {
			ans++
		}
	}
	fmt.Println(ans)
}
開發者ID:kronos,項目名稱:Task-solutions,代碼行數:30,代碼來源:469B.go

示例13: main

func main() {
	var s string
	fmt.Scanf("%s", &s)

	var t string
	fmt.Scanf("%s", &t)

	m := make([]byte, len(s))

	count := 0
	for i := 0; i < len(s); i++ {
		if s[i] != t[i] {
			count += 1
		}
	}

	if count%2 != 0 {
		fmt.Println("impossible")
	} else {
		count = count / 2
		for i := 0; i < len(s); i++ {
			if s[i] != t[i] && count > 0 {
				m[i] = s[i]
				count -= 1
			} else {
				m[i] = t[i]
			}
		}
		fmt.Println(string(m))
	}
}
開發者ID:DmitryTsybin,項目名稱:Study,代碼行數:31,代碼來源:545B_Equidistant_String.go

示例14: login

func login(conn net.Conn) {
	// Username
	fmt.Printf("Enter your name: ")
	fmt.Scanf("%s", &writeStr)
	username := string(writeStr)

	// Password
	fmt.Printf("Enter your password: ")
	fmt.Scanf("%s", &writeStr)
	password := string(writeStr)

	in, err := conn.Write([]byte(username + " " + password))
	if err != nil {
		fmt.Printf("Error when send to server: %d\n", in)
		os.Exit(0)
	}

	length, err := conn.Read(readStr)
	if err != nil {
		fmt.Printf("Error when read from server. Error:%s\n", err)
		os.Exit(0)
	}
	if string(readStr[:length]) == "login error" {
		fmt.Println("Login error, try again.")
		login(conn)
	}

}
開發者ID:magicsea,項目名稱:mygoserver,代碼行數:28,代碼來源:clientMain.go

示例15: main

func main() {
	var T int
	fmt.Scanf("%d\n", &T)

	for i := 0; i < T; i++ {
		//Step 1 read the Main matrix
		var m, n int
		fmt.Scanf("%d %d\n", &m, &n)
		mainMat := readMatrix(m, n)

		//Step 2: Read the pattern Matrix
		var pm, pn int
		fmt.Scanf("%d %d\n", &pm, &pn)
		patternMat := readMatrix(pm, pn)

		//Step 3: search for the pattern
		var res bool = false
	loop:
		for i := 0; i < ((m - pm) + 1); i++ {
			for j := 0; j < ((n - pn) + 1); j++ {
				res = verifyMatch(mainMat, i, j, patternMat, pm, pn)
				if res {
					break loop
				}
			}
		}

		//Step 4: Announce the results
		if res {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}
開發者ID:SuhasAnand,項目名稱:Hckrnk,代碼行數:35,代碼來源:theGridSearch.go


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