d09.go 857 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package main
  2. import "strconv"
  3. import "bufio"
  4. import "fmt"
  5. import "os"
  6. type Compressed struct {
  7. BSize int
  8. Count int
  9. }
  10. func ReadCompressed(line string) *Compressed {
  11. if (line[0] != '(' || line[len(line) -1] != ')') {
  12. return nil
  13. }
  14. line = line[1:len(line)-1]
  15. fmt.Println(">>>" +line +"<<<")
  16. this := new(Compressed)
  17. this.BSize = 0
  18. return this
  19. }
  20. func main() {
  21. reader := bufio.NewReader(os.Stdin)
  22. length := 0
  23. for true {
  24. line, err := reader.ReadString('(')
  25. if line[len(line) -1] == '(' {
  26. line = line[0: len(line) -1]
  27. reader.UnreadByte()
  28. }
  29. length += len(line)
  30. fmt.Println(line)
  31. if err != nil {
  32. break
  33. }
  34. line, err = reader.ReadString(')')
  35. compressed := ReadCompressed(line)
  36. if (compressed == nil) {
  37. length += len(line)
  38. continue
  39. }
  40. if err != nil {
  41. break
  42. }
  43. }
  44. fmt.Println("len: " +strconv.Itoa(length))
  45. }