fork download
  1. package main
  2.  
  3. import (
  4. "math"
  5. "fmt"
  6. "bytes"
  7. "os"
  8. "io/ioutil"
  9. )
  10.  
  11. func main() {
  12. bs, _ := ioutil.ReadAll(os.Stdin)
  13. reader := bytes.NewBuffer(bs)
  14. var a, b, c int64
  15. fmt.Fscanf(reader, "%d %d %d", &a, &b, &c)
  16. delta := b * b - 4 * a * c
  17. if a == 0 && b == 0 && c == 0 {
  18. fmt.Printf("-1")
  19. } else if a == 0 && b == 0 {
  20. fmt.Printf("0")
  21. } else if a == 0 {
  22. fmt.Printf("1\n%f", float64(-c)/float64(b))
  23. } else if delta < 0 {
  24. fmt.Printf("0")
  25. } else if delta == 0 {
  26. fmt.Printf("1\n%f", float64(-b)/float64(2 * a))
  27. } else if delta > 0 {
  28. x1 := (float64(-b) + math.Sqrt(float64(delta))) / float64(2 * a)
  29. x2 := (float64(-b) - math.Sqrt(float64(delta))) / float64(2 * a)
  30. if x1 < x2 {
  31. fmt.Printf("2\n%f\n%f", x1, x2)
  32. } else {
  33. fmt.Printf("2\n%f\n%f", x2, x1)
  34. }
  35. }
  36. }
Success #stdin #stdout 0s 5292KB
stdin
1 -5 2
stdout
2
0.438447
4.561553