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


Golang fmt.Scan函數代碼示例

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


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

示例1: main

func main() {
	// Parse input.
	var count int
	_, err := fmt.Scan(&count)
	if err != nil {
		log.Fatalln(err)
	}
	ns := make([]int, count)
	for i := 0; i < count; i++ {
		_, err = fmt.Scan(&ns[i])
		if err != nil {
			log.Fatalln(err)
		}
	}

	// Check which input numbers that are fibonacci numbers.
	fib := NewFib()
	for _, n := range ns {
		if fib.IsFib(n) {
			fmt.Println("IsFibo")
		} else {
			fmt.Println("IsNotFibo")
		}
	}
}
開發者ID:mewmew,項目名稱:playground,代碼行數:25,代碼來源:is_fibo.go

示例2: main

func main() {
	var N int
	fmt.Scan(&N)

	arr := make([][]int, N)
	for i := 0; i < N; i++ {
		arr[i] = make([]int, N)
		for j := 0; j < N; j++ {
			fmt.Scan(&arr[i][j])
		}
	}

	sum := make([]int, N)
	max := -2147483648
	for i := 0; i < N; i++ {
		copy(sum, arr[i])
		result := maxSum(sum)
		if result > max {
			max = result
		}
		for j := i + 1; j < N; j++ {
			for k := 0; k < N; k++ {
				sum[k] += arr[j][k]
			}
			result := maxSum(sum)
			if result > max {
				max = result
			}
		}
	}

	fmt.Println(max)
}
開發者ID:EagleChen,項目名稱:timus,代碼行數:33,代碼來源:sum.go

示例3: main

func main() {
	for {
		// enemy1: name of enemy 1
		var enemy1 string
		fmt.Scan(&enemy1)

		// dist1: distance to enemy 1
		var dist1 int
		fmt.Scan(&dist1)

		// enemy2: name of enemy 2
		var enemy2 string
		fmt.Scan(&enemy2)

		// dist2: distance to enemy 2
		var dist2 int
		fmt.Scan(&dist2)

		// fmt.Fprintln(os.Stderr, "Debug messages...")

		if dist1 < dist2 {
			fmt.Println(enemy1)
		} else {
			fmt.Println(enemy2)
		}
	}
}
開發者ID:mellowdrifter,項目名稱:codingame.com,代碼行數:27,代碼來源:training.go

示例4: main

func main() {
	var a int
	var b [1000]string
	fmt.Scan(&a)
	for cnt := a; cnt > 0; cnt-- {
		fmt.Scan(&b[cnt-1])
	}
	current := 1
	step := 0
	for cnt := a - 1; cnt >= 0; cnt-- {
		if b[cnt][0] == 'A' || b[cnt][0] == 'P' || b[cnt][0] == 'O' || b[cnt][0] == 'R' {
			if current == 2 {
				step += 1
			} else if current == 3 {
				step += 2
			}
			current = 1
		} else if b[cnt][0] == 'S' || b[cnt][0] == 'M' || b[cnt][0] == 'B' {
			if current != 2 {
				step++
			}
			current = 2
		} else {
			if current == 2 {
				step += 1
			} else if current == 1 {
				step += 2
			}
			current = 3
		}

	}
	fmt.Println(step)
}
開發者ID:gopherboy,項目名稱:online_judge_solutions,代碼行數:34,代碼來源:2023._Donald_is_a_postman.go

示例5: main

func main() {
	var n, a, b int
	fmt.Scan(&n)
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Println(2 * n * a * b)
}
開發者ID:esix,項目名稱:competitive-programming,代碼行數:7,代碼來源:solution.go

示例6: GetNumberSelection

func GetNumberSelection(use_even_numbers bool) int {
	var number string
	if use_even_numbers == true {
		evenNumbers := []string{"2", "4", "6", "8"}
		fmt.Println("\nPlease pick a number", evenNumbers)
		fmt.Scan(&number)
		for {
			for i := range evenNumbers {
				if evenNumbers[i] == number {
					return (i * 2) + 2
				}
			}
			fmt.Println("Your input was invalid. Please pick a number", evenNumbers)
			fmt.Scan(&number)
		}
	} else {
		oddNumbers := []string{"1", "3", "5", "7"}
		fmt.Println("\nPlease pick a number", oddNumbers)
		fmt.Scan(&number)
		for {
			for i := range oddNumbers {
				if oddNumbers[i] == number {
					return (i * 2) + 1
				}
			}
			fmt.Println("Your input was invalid. Please pick a number", oddNumbers)
			fmt.Scan(&number)
		}
	}
}
開發者ID:kseals281,項目名稱:beginnings,代碼行數:30,代碼來源:whirlybird.go

示例7: main

func main() {
	var n int
	fmt.Scan(&n)

	var v [][]int = make([][]int, n)
	for i := range v {
		v[i] = make([]int, n)
	}

	for i := 0; i < n*n; i++ {
		var number int
		fmt.Scan(&number)

		v[i/n][i%n] = number
	}

	var ldSum, rdSum int
	ldSum = 0
	rdSum = 0
	for i := 0; i < n; i++ {
		ldSum += v[i][i]
		rdSum += v[i][n-1-i]
	}

	fmt.Println(math.Abs(float64(ldSum - rdSum)))
}
開發者ID:writecoffee,項目名稱:random_practice,代碼行數:26,代碼來源:diagonal_difference.go

示例8: main

func main() {

	var n int
	fmt.Scan(&n)

	cardsp1 = make([]string, n)

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

		var cardp1 string
		fmt.Scan(&cardp1)

		cardsp1[i] = cardp1
	}

	var m int
	fmt.Scan(&m)

	cardsp2 = make([]string, m)

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

		var cardp2 string
		fmt.Scan(&cardp2)

		cardsp2[i] = cardp2
	}

	winner := "PAT"

	battlesFought = 0
	i = 0

	for {

		result := battle()
		fmt.Fprintf(os.Stderr, "battle %d result: %s\n", battlesFought, battleResultStrings[result])

		if result == battle_p2_out_of_cards {
			winner = "1"
			break
		}

		if result == battle_p1_out_of_cards {
			winner = "2"
			break
		}

		if result == battle_draw {
			winner = "PAT"
			break
		}
	}

	if winner == "PAT" {
		fmt.Println("PAT")
	} else {
		fmt.Printf("%s %d\n", winner, battlesFought)
	}
}
開發者ID:israelchen,項目名稱:CodinGame,代碼行數:60,代碼來源:codingame-Winamax_WAR.go

示例9: Scan

func (f *Field) Scan() error {
	var attrs string
	var err error
	fmt.Print(correctTypes, "?: ")
	for true {
		fmt.Scanln(&f.Type)
		f.Type = strings.ToLower(f.Type)
		if varutil.IsArrContainStr(correctTypes, f.Type) {
			break
		}
		fmt.Print(correctTypes, "?: ")
	}
	fmt.Print("Min value of field: ")
	fmt.Scan(&f.Min)
	fmt.Print("Max value of field: ")
	fmt.Scan(&f.Max)

	var isAttrs string
	fmt.Print("Do you want add attribiutes? ")
	fmt.Scan(&isAttrs)
	isAttrs = strings.ToLower(isAttrs)
	if isAttrs == "yes" || isAttrs == "y" {
		fmt.Print("Insert field attrs (separated with space): ")
		fmt.Scan(&attrs)
		f.Attrs, err = varutil.SplitWhite(attrs)
		if err != nil {
			return err
		}
	}
	return nil
}
開發者ID:goatcms,項目名稱:goat,代碼行數:31,代碼來源:field.go

示例10: main

func main() {
	var n int
	fmt.Scan(&n)
	x, y, r := make([]float64, n), make([]float64, n), make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&x[i])
		fmt.Scan(&y[i])
		fmt.Scan(&r[i])
		r[i] *= r[i]
	}
	var c int
	for i := 0; i < 1000; i++ {
		for j := 0; j < 1000; j++ {
			x1 := (float64(i) + 0.5) / 1000.0
			y1 := (float64(j) + 0.5) / 1000.0
			var k int
			for ; k < n && dist(x1, y1, x[k], y[k]) > r[k]; k++ {
			}
			if k < n {
				c++
			}
		}
	}
	fmt.Printf("%.6f\n", float64(c)*100.0/1000000)
}
開發者ID:ferhatelmas,項目名稱:algo,代碼行數:25,代碼來源:1333.go

示例11: main

func main() {
	var a, b string
	fmt.Scan(&a)
	fmt.Scan(&b)

	fmt.Println(getDeletes(a, b))
}
開發者ID:sbani,項目名稱:hackerrank,代碼行數:7,代碼來源:solution.go

示例12: main

func main() {
	var k int
	fmt.Scan(&k)
	c := make([]int64, k)
	for i := 0; i < k; i++ {
		fmt.Scan(&c[i])
		if i > 0 {
			c[i] += c[i-1]
		}
	}
	var m = c[k-1]
	fact := make([]int64, c[k-1])
	fact[0] = 1
	for i := int64(1); i < m; i++ {
		fact[i] = fact[i-1] * i % mod
	}
	ans := int64(1)
	var n int64
	for i := 1; i < k; i++ {
		n = c[i] - 1
		m = c[i] - c[i-1] - 1
		ans = ans * fact[n] % mod * fastPow(fact[m]*fact[n-m]%mod, mod-2) % mod
	}
	fmt.Println(ans)
}
開發者ID:jefferyyuan,項目名稱:Cookie,代碼行數:25,代碼來源:CF553A+Kyoya+and+Colored+Balls.go

示例13: main

func main() {
	var T int
	fmt.Scan(&T)
	for t := 1; t <= T; t++ {
		var N int
		fmt.Scan(&N)
		words := make([]string, N)
		for i := 0; i < N; i++ {
			fmt.Scan(&words[i])
		}
		// dedupe check
		if !possible(words) {
			fmt.Printf("Case #%d: Fegla Won\n", t)
		} else {
			sum := 0
			groups := make([][]int, N)
			for i := 0; i < N; i++ {
				groups[i] = partition(words[i])
			}
			// only works for n = 2
			for i := 0; i < len(groups[0]); i++ {
				if groups[0][i] > groups[1][i] {
					sum += groups[0][i] - groups[1][i]
				} else if groups[1][i] > groups[0][i] {
					sum += groups[1][i] - groups[0][i]
				}
			}

			fmt.Printf("Case #%d: %d\n", t, sum)
		}
	}
}
開發者ID:hyPiRion,項目名稱:contests,代碼行數:32,代碼來源:repeater.go

示例14: main

func main() {
	var n, s int
	fmt.Scan(&n)
	fmt.Scan(&s)
	if s%2 == 1 {
		fmt.Println(0)
	} else {
		s /= 2
		dp := make([][]*big.Int, n+1, n+1)
		for i := 0; i <= n; i++ {
			dp[i] = make([]*big.Int, s+1, s+1)
			for j := 0; j <= s; j++ {
				dp[i][j] = &big.Int{}
			}
		}
		dp[0][0] = big.NewInt(1)
		for i := 1; i <= n; i++ {
			for j := 0; j <= s; j++ {
				for k := 0; k <= up(j); k++ {
					dp[i][j].Add(dp[i][j], dp[i-1][j-k])
				}
			}
		}
		fmt.Println(dp[n][s].Mul(dp[n][s], dp[n][s]))
	}
}
開發者ID:ferhatelmas,項目名稱:algo,代碼行數:26,代碼來源:1036.go

示例15: main

func main() {
	size := 0
	fmt.Scan(&size)
	data := make([]int, size)
	isNegative := true
	for i := 0; i < size; i++ {
		fmt.Scan(&data[i])
		if data[i] >= 0 {
			isNegative = false
		}
	}

	thisSum, maxSum := 0, 0
	thisSub := make([]int, 0)
	maxSub := make([]int, 1)
	for _, v := range data {
		thisSum += v
		thisSub = append(thisSub, v)
		if thisSum > maxSum {
			maxSum = thisSum
			maxSub = append([]int{}, thisSub...)
		} else if thisSum < 0 {
			thisSum = 0
			thisSub = []int{}
		}
	}

	if isNegative {
		fmt.Println(0, data[0], data[size-1])
	} else {
		fmt.Println(maxSum, maxSub[0],
			maxSub[len(maxSub)-1])
	}
}
開發者ID:C02Q5Y7HFVH3,項目名稱:ds,代碼行數:34,代碼來源:02.go


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