本文整理匯總了Golang中fmt.Fscan函數的典型用法代碼示例。如果您正苦於以下問題:Golang Fscan函數的具體用法?Golang Fscan怎麽用?Golang Fscan使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Fscan函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
func main() {
//Enter your code here. Read input from STDIN. Print output to STDOUT
var T, N, M, p1, p2 int
io := bufio.NewReader(os.Stdin)
fmt.Fscan(io, &T)
for T > 0 {
adjm := initialize(100, 6)
fmt.Fscan(io, &N)
for i := 0; i < N; i++ {
fmt.Fscan(io, &p1, &p2)
adjm[p1-1][p2-1] = 0
}
fmt.Fscan(io, &M)
for i := 0; i < M; i++ {
fmt.Fscan(io, &p1, &p2)
adjm[p1-1][p2-1] = 0
for j := 1; j <= 6; j++ {
if (p1 - 1 + j) > 100-1 {
break
}
adjm[p1-1][p1-1+j] = 101
}
}
dist := floydWarshall(adjm, 100)
if dist[0][99] == 101 {
fmt.Println("-1")
} else {
fmt.Println(dist[0][99])
}
T--
}
}
示例2: GetUserAnswer
func (v Video) GetUserAnswer() int {
var answer int
stdin := bufio.NewReader(os.Stdin)
fmt.Println("Title:", v.Title)
fmt.Println("Description:", v.Description)
fmt.Println("Available qualities: ")
for i := 0; i < len(v.Links); i++ {
fmt.Println(i+1, "Quality:", v.Links[i].Quality, "\tSize:", toMB(v.Links[i].Size), "MB")
}
fmt.Printf("Which quality do you want to donwload?")
_, err := fmt.Fscan(stdin, &answer)
stdin.ReadString('\n')
if err != nil {
fmt.Println(err)
os.Exit(1)
}
for answer < 1 || answer > len(v.Links) {
fmt.Printf("Invalid choice!")
_, err := fmt.Fscan(stdin, &answer)
stdin.ReadString('\n')
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
return answer
}
示例3: DecodePolygon
// DecodePolygon loads a polygon saved using EncodePolygon function.
func DecodePolygon(in io.Reader) (*polyclip.Polygon, error) {
var ncontours int
_, err := fmt.Fscan(in, &ncontours)
if err != nil {
return nil, err
}
polygon := polyclip.Polygon{}
for i := 0; i < ncontours; i++ {
var npoints, level int
_, err = fmt.Fscan(in, &npoints, &level)
if err != nil {
return nil, err
}
c := polyclip.Contour{}
for j := 0; j < npoints; j++ {
p := polyclip.Point{}
_, err = fmt.Fscan(in, &p.X, &p.Y)
if err != nil {
return nil, err
}
if j > 0 && p.Equals(c[len(c)-1]) {
continue
}
if j == npoints-1 && p.Equals(c[0]) {
continue
}
c.Add(p)
}
if len(c) < 3 {
continue
}
polygon.Add(c)
}
return &polygon, nil
}
示例4: reader
func reader() {
file, err := os.Open("input.txt")
if err != nil {
panic(err)
}
defer file.Close()
var scan struct {
A, B float32
C bool
D string
}
log.Printf("scan: %v", scan)
fmt.Fscan(file, &scan.A, &scan.B)
log.Printf("scan: %v", scan)
fmt.Fscan(file, &scan.C, &scan.D)
log.Printf("scan: %v", scan)
fmt.Fscanln(file, &scan.A, &scan.B, &scan.C, &scan.D)
log.Printf("scan: %v", scan)
fmt.Fscanf(file, "The Green %s %f %t %f", &scan.D, &scan.B, &scan.C, &scan.A)
log.Printf("scan: %v", scan)
}
示例5: init
func init() {
merkkiRuuduksi := map[rune]Ruutu{
'#': Seinä,
'.': Tyhjä,
'o': Kivi,
'x': Kuoppa,
'p': Pelaaja,
'm': Maali,
}
file, err := os.Open("testitaso.mp")
if err != nil {
panic("En saanut ladattua tasoa: " + err.Error())
}
fmt.Fscan(file, &kartanLeveys, &kartanKorkeus, &PelaajaX, &PelaajaY)
kartta = make([]Ruutu, kartanLeveys*kartanKorkeus)
for y := 0; y < kartanKorkeus; y++ {
var rivi string
fmt.Fscan(file, &rivi)
for x, merkki := range rivi {
LaitaKartanKohtaan(x, y, merkkiRuuduksi[merkki])
}
}
}
示例6: constructKeys
func (self *node) constructKeys(file *os.File, keyCnt int, typ int) {
var key common.CellValue
var intval common.IntVal
var fltval common.FltVal
var strval common.StrVal
for i := 0; i < keyCnt; i++ {
switch typ {
case common.IntCol:
fmt.Fscan(file, &intval)
key = intval
case common.FltCol:
fmt.Fscan(file, &fltval)
key = fltval
case common.StrCol:
fmt.Fscan(file, &strval)
key = strval
}
self.keys = append(self.keys, key)
}
var recordId int64
if self.isLeaf() {
for i := 0; i < keyCnt; i++ {
fmt.Fscan(file, &recordId)
self.recordIds = append(self.recordIds, recordId)
}
}
}
示例7: grade
func grade(in io.Reader) []byte {
var n, m int
fmt.Fscanln(in, &n, &m)
records := []record{}
var overallavg float64
for i := 0; i < n; i++ {
r := record{}
fmt.Fscan(in, &r.name)
for j := 0; j < m; j++ {
var tmp float64
fmt.Fscan(in, &tmp)
r.grades = append(r.grades, tmp)
r.avg += tmp
}
r.avg /= float64(len(r.grades))
overallavg += r.avg
records = append(records, r)
}
overallavg /= float64(n)
o := new(bytes.Buffer)
fmt.Fprintf(o, "%.2f\n", overallavg)
for _, r := range records {
fmt.Fprintf(o, "%s %.2f\n", r.name, r.avg)
}
return o.Bytes()
}
示例8: main
func main() {
h := &IntHeap{}
heap.Init(h)
dict := map[int]bool{}
var inputSize int
var diff int
io := bufio.NewReader(os.Stdin)
fmt.Fscan(io, &inputSize)
fmt.Fscan(io, &diff)
for i := 0; i < inputSize; i++ {
var number int
fmt.Fscan(io, &number)
heap.Push(h, number)
dict[number] = true
}
pairCount := 0
for i := 0; h.Len() > 0; i++ {
curr := heap.Pop(h).(int)
_, ok := dict[curr+diff]
if ok {
pairCount++
}
}
fmt.Println(pairCount)
}
示例9: main
func main() {
bi := bufio.NewReader(os.Stdin)
bo := bufio.NewWriter(os.Stdout)
defer bo.Flush()
var n, m int
fmt.Fscanln(bi, &n, &m)
g := make([]int, n)
for i := range g {
fmt.Fscan(bi, &g[i])
}
b := make([]int, m)
for i := range b {
fmt.Fscan(bi, &b[i])
}
sort.Ints(g)
sort.Ints(b)
res := sum(g) // no one takes
for k := 1; k <= min(len(b), len(g)); k++ {
new_res := sum(g[:len(g)-k]) + sum(b[:len(b)-k])*k
if new_res < res {
res = new_res
}
}
fmt.Fprintln(bo, res)
}
示例10: main
func main() {
var inputSize int
io := bufio.NewReader(os.Stdin)
fmt.Fscan(io, &inputSize)
var maxDiff int
var firstStr string
var secondStr string
for i := 0; i < inputSize; i++ {
fmt.Fscan(io, &maxDiff)
fmt.Fscan(io, &firstStr)
fmt.Fscan(io, &secondStr)
best := 0
for j := 0; j < len(firstStr); j++ {
best1 := getBest(firstStr, secondStr, 0, j, maxDiff)
best2 := getBest(firstStr, secondStr, j, 0, maxDiff)
if best1 > best && best1 >= best2 {
best = best1
}
if best2 > best && best2 >= best1 {
best = best2
}
}
fmt.Println(best)
}
}
示例11: readCages
func (s *Sudoku) readCages(f *os.File) error {
var ncages int
fmt.Fscan(f, &ncages)
s.Cages = make([]*Cage, ncages)
for i := 0; i < ncages; i++ {
var sum int8
var ncells int
fmt.Fscan(f, &sum, &ncells)
cage := &Cage{
Sum: sum,
Cells: make([]*Cell, ncells),
}
var row, col int8
for j := 0; j < ncells; j++ {
fmt.Fscanf(f, "%d,%d", &col, &row)
cage.Cells[j] = &Cell{
Row: row,
Col: col,
}
}
s.Cages[i] = cage
}
return nil
}
示例12: main
func main() {
var userURL string
stdin := bufio.NewReader(os.Stdin)
fmt.Println("Enter a valid URL:")
_, err := fmt.Fscan(stdin, &userURL)
stdin.ReadString('\n')
if err != nil {
fmt.Println(err)
os.Exit(1)
}
for len(userURL) == 0 {
fmt.Println("[!] URL can't be empty!")
_, err := fmt.Fscan(stdin, &userURL)
stdin.ReadString('\n')
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
response := url.GetPageSource(userURL)
videoUser := url.GetVideoDetails(response)
videoNumber := videoUser.GetUserAnswer()
url.DownloadFile(videoUser.Links[videoNumber-1].Type, videoUser)
}
示例13: getEventId
func getEventId(sysCall string) uint32 {
f, err := os.Open(TracePath + EventPath + "/" + sysCall + "/format")
if err != nil {
log.Fatal(err)
}
defer f.Close()
var token string
for {
_, err = fmt.Fscan(f, &token)
if err != nil {
log.Fatal(err)
}
if token == "ID:" {
_, err = fmt.Fscan(f, &token)
if err != nil {
log.Fatal(err)
}
v, err := strconv.Atoi(token)
if err != nil {
log.Fatal(err)
}
return uint32(v)
}
}
}
示例14: load
func load(stdin io.Reader) {
var t int
fmt.Fscan(stdin, &t)
for i := 0; i < t; i++ {
var n, c, m int
fmt.Fscan(stdin, &n, &c, &m)
fmt.Println(solve(n, c, m))
}
}
示例15: load
func load(stdin io.Reader) {
var t int
fmt.Fscan(stdin, &t)
for i := 0; i < t; i++ {
var a, b int
fmt.Fscan(stdin, &a, &b)
fmt.Println(a + b)
}
}