Решение на Разлика в сумите от Дамян Димитров

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

Към профила на Дамян Димитров

Резултати

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

Код

package main
import "strings"
func GetLogRows(logContents string) (logRows []string) {
logRows = strings.Split(logContents, "\n")
if logRows[len(logRows)-1] == "" {
logRows = logRows[:(len(logRows) - 1)]
}
return
}
func ExtractColumn(logContents string, column uint8) (logColumn string) {
for _, row := range GetLogRows(logContents) {
if row == "" {
break
}
if column == 0 {
logColumn += strings.Join(strings.SplitN(row, " ", 3)[:2], " ") + "\n"
} else {
logColumn += strings.SplitN(row, " ", 4)[column+1] + "\n"
}
}
return
}

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

PASS
ok  	_/tmp/d20151103-24541-tsatnp	0.003s
PASS
ok  	_/tmp/d20151103-24541-tsatnp	0.003s
PASS
ok  	_/tmp/d20151103-24541-tsatnp	0.003s
PASS
ok  	_/tmp/d20151103-24541-tsatnp	0.003s
PASS
ok  	_/tmp/d20151103-24541-tsatnp	0.003s
PASS
ok  	_/tmp/d20151103-24541-tsatnp	0.003s
PASS
ok  	_/tmp/d20151103-24541-tsatnp	0.003s
PASS
ok  	_/tmp/d20151103-24541-tsatnp	0.003s
PASS
ok  	_/tmp/d20151103-24541-tsatnp	0.003s
PASS
ok  	_/tmp/d20151103-24541-tsatnp	0.003s
PASS
ok  	_/tmp/d20151103-24541-tsatnp	0.003s
PASS
ok  	_/tmp/d20151103-24541-tsatnp	0.003s
PASS
ok  	_/tmp/d20151103-24541-tsatnp	0.003s
PASS
ok  	_/tmp/d20151103-24541-tsatnp	0.003s
PASS
ok  	_/tmp/d20151103-24541-tsatnp	0.003s

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

Дамян обнови решението на 29.10.2015 14:07 (преди над 2 години)

+package main
+
+import "strings"
+
+func GetLogRows(logContents string) (logRows []string) {
+ logRows = strings.Split(logContents, "\n")
+ if logRows[len(logRows)-1] == "" {
+ logRows = logRows[:(len(logRows) - 1)]
+ }
+ return
+}
+
+func ExtractColumn(logContents string, column uint8) (logColumn string) {
+ for _, row := range GetLogRows(logContents) {
+ if row == "" {
+ break
+ }
+ if column == 0 {
+ logColumn += strings.SplitN(row, " ", 4)[0] + " " + strings.SplitN(row, " ", 4)[1] + "\n"
+ } else {
+ logColumn += strings.SplitN(row, " ", 4)[column+1] + "\n"
+ }
+ }
+ return
+}

Дамян обнови решението на 29.10.2015 22:12 (преди над 2 години)

package main
import "strings"
func GetLogRows(logContents string) (logRows []string) {
logRows = strings.Split(logContents, "\n")
if logRows[len(logRows)-1] == "" {
logRows = logRows[:(len(logRows) - 1)]
}
return
}
func ExtractColumn(logContents string, column uint8) (logColumn string) {
for _, row := range GetLogRows(logContents) {
if row == "" {
break
}
if column == 0 {
- logColumn += strings.SplitN(row, " ", 4)[0] + " " + strings.SplitN(row, " ", 4)[1] + "\n"
+ logColumn += strings.Join(strings.SplitN(row, " ", 3)[:2], " ") + "\n"
} else {
logColumn += strings.SplitN(row, " ", 4)[column+1] + "\n"
}
}
return
}