Guest User

Untitled

a guest
May 30th, 2020
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.64 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "bufio"
  5.     "fmt"
  6.     "os"
  7.     "strconv"
  8. )
  9.  
  10. func output(result string) {
  11.     fmt.Println(result)
  12.     f, _ := os.Create("output.txt")
  13.     defer f.Close()
  14.     f.WriteString(result)
  15. }
  16.  
  17. func main() {
  18.     file, _ := os.Open("input.txt")
  19.     defer file.Close()
  20.  
  21.     scanner := bufio.NewScanner(file)
  22.     scanner.Split(bufio.ScanWords)
  23.  
  24.     scanner.Scan()
  25.     target, _ := strconv.Atoi(scanner.Text())
  26.  
  27.     m := make(map[int]struct{})
  28.     for scanner.Scan() {
  29.         num, _ := strconv.Atoi(scanner.Text())
  30.         if num > target {
  31.             continue
  32.         }
  33.         if _, found := m[target-num]; found {
  34.             output("1")
  35.             return
  36.         }
  37.         m[num] = struct{}{}
  38.     }
  39.  
  40.     output("0")
  41. }
Advertisement
Add Comment
Please, Sign In to add comment