interface_task2.go 369 B

123456789101112131415161718192021222324
  1. package main
  2. import (
  3. "fmt"
  4. "strings"
  5. )
  6. type battery uint8
  7. func (b *battery) set(str string) {
  8. *b = battery(strings.Count(str, `1`))
  9. }
  10. func (b battery) String() string {
  11. return fmt.Sprintf("[%10s]", strings.Repeat("X", int(b)))
  12. }
  13. func main() {
  14. var batteryForTest battery
  15. var str string
  16. fmt.Scan(&str)
  17. batteryForTest.set(str)
  18. fmt.Println(batteryForTest)
  19. }