本文整理匯總了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")
}
}
}
示例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)
}
示例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)
}
}
}
示例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)
}
示例5: main
func main() {
var n, a, b int
fmt.Scan(&n)
fmt.Scan(&a)
fmt.Scan(&b)
fmt.Println(2 * n * a * b)
}
示例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)
}
}
}
示例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)))
}
示例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)
}
}
示例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
}
示例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)
}
示例11: main
func main() {
var a, b string
fmt.Scan(&a)
fmt.Scan(&b)
fmt.Println(getDeletes(a, b))
}
示例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)
}
示例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)
}
}
}
示例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]))
}
}
示例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])
}
}