本文整理汇总了Golang中fmt.Scan函数的典型用法代码示例。如果您正苦于以下问题:Golang Scan函数的具体用法?Golang Scan怎么用?Golang Scan使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Scan函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: main
func main() {
var n, q int
d := make(map[string]string)
fmt.Scan(&q)
for i := 0; i < q; i++ {
var oldH, newH string
fmt.Scan(&oldH, &newH)
origH, exists := d[oldH]
if exists {
d[newH] = origH
delete(d, oldH)
} else {
d[newH] = oldH
n++
}
}
fmt.Println(n)
for newH, oldH := range d {
fmt.Println(oldH, newH)
}
}
开发者ID:Vicissitude47,项目名称:codeforces-solutions,代码行数:28,代码来源:501b.go
示例17: main
func main() {
var N int
fmt.Scan(&N)
powers := make([]int, 0)
for i := 0; i < N; i++ {
var Pi int
fmt.Scan(&Pi)
if Pi > 0 {
powers = append(powers, Pi)
fmt.Fprintln(os.Stderr, Pi)
}
}
fmt.Fprintln(os.Stderr, powers)
sort.Ints(powers)
minD := 99999999999
for i := 1; i < len(powers); i++ {
delta := int(math.Abs(float64(powers[i] - powers[i-1])))
if delta < minD {
minD = delta
}
}
fmt.Fprintln(os.Stderr, powers)
fmt.Println(minD) // Write answer to stdout
}
开发者ID:israelchen,项目名称:CodinGame,代码行数:35,代码来源:codingame-Horse_Racing_Duals.go
示例18: main
func main() {
var t int
var s []byte
fmt.Scan(&t)
if t < 1 || t > 100 {
return
}
for i := 0; i < t; i++ {
fmt.Scan(&s)
var r []byte
for j := len(s) - 1; j > -1; j-- {
r = append(r, s[j])
}
var flag int
for j := 1; j < len(s); j++ {
if absDif(s[j], s[j-1]) != absDif(r[j], r[j-1]) {
flag = 1
fmt.Println("Not Funny")
break
}
}
if flag == 0 {
fmt.Println("Funny")
}
}
}
开发者ID:decebal,项目名称:go-training,代码行数:29,代码来源:funny_string.go
示例19: main
func main() {
var t int
fmt.Scan(&t)
for cas := 1; cas <= t; cas++ {
var pig, all, n int
fmt.Scan(&pig, &all, &n)
all -= pig
for i := 0; i < n; i++ {
fmt.Scan(&v[i], &w[i])
}
for i := 1; i <= all; i++ {
dp[i] = INF
}
for i := 0; i < n; i++ {
for j := w[i]; j <= all; j++ {
dp[j] = min(dp[j], dp[j-w[i]]+v[i])
}
}
if dp[all] != INF {
fmt.Printf("The minimum amount of money in the piggy-bank is %d.\n", dp[all])
} else {
fmt.Println("This is impossible.")
}
}
}
开发者ID:ronaflx,项目名称:OJs,代码行数:25,代码来源:PIGBANK.go
示例20: main
func main() {
var n, m, k int
var dp [2][1001]node
fmt.Scan(&n)
fmt.Scan(&m)
fmt.Scan(&k)
nodes := make(map[node]bool, k)
for i := 0; i < k; i++ {
var x node
fmt.Scan(&x.a, &x.b)
nodes[x] = true
}
for i := 0; i <= m; i++ {
dp[0][i] = node{i, 0}
}
for i := 1; i <= n; i++ {
x := i & 1
dp[x][0] = node{i, 0}
for j := 1; j <= m; j++ {
dp[x][j] = node{1, 0}.add(dp[x^1][j].min(dp[x][j-1]))
if nodes[node{i, j}] {
dp[x][j] = dp[x][j].min(dp[x^1][j-1].add(node{0, 1}))
}
}
}
fmt.Printf("%.0f\n", 100*dp[n&1][m].res())
}
开发者ID:ferhatelmas,项目名称:algo,代码行数:29,代码来源:1119.go
注:本文中的fmt.Scan函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论