Решение на Разлика в сумите от Радослав Георгиев

Обратно към всички решения

Към профила на Радослав Георгиев

Резултати

  • 10 точки от тестове
  • 0 бонус точки
  • 10 точки общо
  • 15 успешни тест(а)
  • 0 неуспешни тест(а)

Код

package main
import (
"bufio"
"bytes"
"strings"
)
func ExtractColumn(logContents string, column uint8) string {
var buffer bytes.Buffer
scanner := bufio.NewScanner(strings.NewReader(logContents))
for scanner.Scan() {
line := scanner.Text()
if line == "" {
continue
}
cols := strings.Split(line, " ")
switch column {
case 0:
buffer.WriteString(cols[0])
buffer.WriteString(" ")
buffer.WriteString(cols[1])
case 1:
buffer.WriteString(cols[2])
case 2:
buffer.WriteString(cols[3])
colCount := len(cols)
for j := 4; j < colCount; j++ {
buffer.WriteString(" ")
buffer.WriteString(cols[j])
}
}
buffer.WriteString("\n")
}
return buffer.String()
}

Лог от изпълнението

PASS
ok  	_/tmp/d20151103-24541-1i1t0hy	0.003s
PASS
ok  	_/tmp/d20151103-24541-1i1t0hy	0.003s
PASS
ok  	_/tmp/d20151103-24541-1i1t0hy	0.003s
PASS
ok  	_/tmp/d20151103-24541-1i1t0hy	0.003s
PASS
ok  	_/tmp/d20151103-24541-1i1t0hy	0.003s
PASS
ok  	_/tmp/d20151103-24541-1i1t0hy	0.003s
PASS
ok  	_/tmp/d20151103-24541-1i1t0hy	0.003s
PASS
ok  	_/tmp/d20151103-24541-1i1t0hy	0.003s
PASS
ok  	_/tmp/d20151103-24541-1i1t0hy	0.003s
PASS
ok  	_/tmp/d20151103-24541-1i1t0hy	0.003s
PASS
ok  	_/tmp/d20151103-24541-1i1t0hy	0.003s
PASS
ok  	_/tmp/d20151103-24541-1i1t0hy	0.003s
PASS
ok  	_/tmp/d20151103-24541-1i1t0hy	0.003s
PASS
ok  	_/tmp/d20151103-24541-1i1t0hy	0.003s
PASS
ok  	_/tmp/d20151103-24541-1i1t0hy	0.003s

История (2 версии и 0 коментара)

Радослав обнови решението на 29.10.2015 11:36 (преди над 2 години)

+package main
+
+import (
+ "bufio"
+ "bytes"
+ "strings"
+)
+
+func ExtractColumn(logContents string, column uint8) string {
+ var buffer bytes.Buffer
+ scanner := bufio.NewScanner(strings.NewReader(logContents))
+
+ for scanner.Scan() {
+ line := scanner.Text()
+
+ if line == "" {
+ continue
+ }
+
+ cols := strings.Split(line, " ")
+
+ switch column {
+ case 0:
+ buffer.WriteString(cols[0])
+ buffer.WriteString(" ")
+ buffer.WriteString(cols[1])
+ case 1:
+ buffer.WriteString(cols[2])
+ case 2:
+ buffer.WriteString(cols[3])
+
+ for j := 4; j < len(cols); j++ {
+ buffer.WriteString(" ")
+ buffer.WriteString(cols[j])
+ }
+ }
+
+ buffer.WriteString("\n")
+ }
+
+ return buffer.String()
+}

Радослав обнови решението на 03.11.2015 14:16 (преди над 2 години)

package main
import (
"bufio"
"bytes"
"strings"
)
func ExtractColumn(logContents string, column uint8) string {
var buffer bytes.Buffer
scanner := bufio.NewScanner(strings.NewReader(logContents))
for scanner.Scan() {
line := scanner.Text()
if line == "" {
continue
}
cols := strings.Split(line, " ")
switch column {
case 0:
buffer.WriteString(cols[0])
buffer.WriteString(" ")
buffer.WriteString(cols[1])
case 1:
buffer.WriteString(cols[2])
case 2:
buffer.WriteString(cols[3])
+ colCount := len(cols)
- for j := 4; j < len(cols); j++ {
+ for j := 4; j < colCount; j++ {
buffer.WriteString(" ")
buffer.WriteString(cols[j])
}
}
buffer.WriteString("\n")
}
return buffer.String()
}