本文整理汇总了Golang中fmt.Scanf函数的典型用法代码示例。如果您正苦于以下问题:Golang Scanf函数的具体用法?Golang Scanf怎么用?Golang Scanf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Scanf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: main
func main() {
var rockSize int
fmt.Scanf("%d", &rockSize)
var gemElemSet = make(map[string]bool)
for i := 0; i < rockSize; i++ {
var input string
fmt.Scanf("%s", &input)
if i == 0 {
for _, j := range input {
_, ok := gemElemSet[string(j)]
if !ok {
gemElemSet[string(j)] = true
}
}
} else {
for element, _ := range gemElemSet {
if !strings.Contains(input, element) {
delete(gemElemSet, element)
}
}
}
}
fmt.Println(len(gemElemSet))
}
开发者ID:knd,项目名称:hackerrank,代码行数:25,代码来源:GemStones.go
示例17: main
func main() {
var name string // Need vars so we can store scanf results
var age int
// Read some input
fmt.Print("Gimme name :")
fmt.Scanf("%s", &name) // Using a specific verb and passing a pointer to the name var
fmt.Print("Gimme age :")
fmt.Scanf("%d", &age) // Different verb for a number
p := person{name: name, age: age} // Using composite literal to create with named members, could pass just vals based on sequence, if using named members can do so in any order, could use new(person) which would give us a pointer
fmt.Printf("p %v\n", p) // Toggle String() method name to show how person is satisying the stringer interface and how this affects output
fmt.Println()
passByVal(p)
fmt.Printf("\tp after passByVal : %v\n", p)
fmt.Println()
passByPointer(&p) // Need &p to get a pointer to p as the function expects a *person
fmt.Printf("\tp after passByPointer : %v\n", p)
fmt.Println()
makeHowlerHowl(p) // Pass person to function expecting an interface, since person has a howl method that matches the interface we are good
}
开发者ID:pmcgrath,项目名称:presentations,代码行数:25,代码来源:hellostruct.go
示例18: main
func main() {
var t int
fmt.Scanf("%d", &t)
outer:
for j := 0; j < t; j++ {
var str1, str2 string
fmt.Scanf("%s", &str1)
fmt.Scanf("%s", &str2)
var arr [26]bool
for i := 0; i < 26; i++ {
arr[i] = false
}
for i := 0; i < len(str1); i++ {
arr[str1[i]-'a'] = true
}
for i := 0; i < len(str2); i++ {
if arr[str2[i]-'a'] {
fmt.Println("YES")
//countine=ue outer
continue outer
}
}
fmt.Println("NO")
}
}
开发者ID:ankcrimson,项目名称:Practice,代码行数:33,代码来源:TwoStrings.go
示例19: UpdatePasswordUsingCAS
func UpdatePasswordUsingCAS(client *Client) {
// Get username
var username string
fmt.Print("Enter username:")
fmt.Scanf("%s", &username)
if len(username) > 0 {
// Check if username exists
userKey, _ := NewKey("test", "users", username)
userRecord, err := client.Get(nil, userKey)
panicOnError(err)
if err == nil {
// Get new password
var password string
fmt.Print("Enter new password for %s:", username)
fmt.Scanf("%s", &password)
writePolicy := NewWritePolicy(0, 0) // generation = 0, expiration = 0
// record generation
writePolicy.Generation = int32(userRecord.Generation)
writePolicy.GenerationPolicy = EXPECT_GEN_EQUAL
// password Bin
passwordBin := NewBin("password", password)
err = client.PutBins(writePolicy, userKey, passwordBin)
panicOnError(err)
fmt.Printf("\nINFO: The password has been set to: %s", password)
} else {
fmt.Printf("ERROR: User record not found!")
}
} else {
fmt.Printf("ERROR: User record not found!")
}
}
开发者ID:rmondragon,项目名称:student-workbook,代码行数:34,代码来源:tweetaspike.go
示例20: queryUsersByTweetCount
func queryUsersByTweetCount(client *Client) {
fmt.Printf("\n********** Query Users By Tweet Count Range **********\n")
// Get min and max tweet counts
var min int64
var max int64
fmt.Printf("\nEnter Min Tweet Count:")
fmt.Scanf("%d", &min)
fmt.Printf("Enter Max Tweet Count:")
fmt.Scanf("%d", &max)
fmt.Printf("\nList of users with %d - %d tweets:\n", min, max)
stmt := NewStatement("test", "users", "username", "tweetcount", "gender")
stmt.Addfilter(NewRangeFilter("tweetcount", min, max))
recordset, err := client.Query(nil, stmt)
panicOnError(err)
L:
for {
select {
case rec, chanOpen := <-recordset.Records:
if !chanOpen {
break L
}
fmt.Printf("%s has %d tweets\n", rec.Bins["username"], rec.Bins["tweetcount"])
case err := <-recordset.Errors:
panicOnError(err)
}
}
recordset.Close()
}
开发者ID:rmondragon,项目名称:student-workbook,代码行数:33,代码来源:tweetaspike.go
注:本文中的fmt.Scanf函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论