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

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

Към профила на Андрея Костов

Резултати

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

Код

package main
import "strings"
func ExtractColumn(logContents string, column uint8) (result string) {
lines := strings.Split(logContents, "\n")
lineLength := len(lines)
var getContent func(s string) string
switch {
case column == 0:
getContent = func(s string) string { return s[:19] }
case column == 1:
getContent = func(s string) string {
subs := s[20:len(s)]
subs = subs[:strings.Index(subs, " ")]
return subs
}
case column == 2:
getContent = func(s string) string {
subs := s[20:len(s)]
subs = subs[strings.Index(subs, " ")+1 : len(subs)]
return subs
}
}
for i := 0; i < lineLength; i++ {
if lines[i] != "" {
result += getContent(lines[i]) + "\n"
}
}
return
}

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

PASS
ok  	_/tmp/d20151103-24541-ityp8y	0.003s
PASS
ok  	_/tmp/d20151103-24541-ityp8y	0.003s
PASS
ok  	_/tmp/d20151103-24541-ityp8y	0.003s
PASS
ok  	_/tmp/d20151103-24541-ityp8y	0.003s
PASS
ok  	_/tmp/d20151103-24541-ityp8y	0.004s
PASS
ok  	_/tmp/d20151103-24541-ityp8y	0.003s
PASS
ok  	_/tmp/d20151103-24541-ityp8y	0.003s
PASS
ok  	_/tmp/d20151103-24541-ityp8y	0.003s
PASS
ok  	_/tmp/d20151103-24541-ityp8y	0.003s
PASS
ok  	_/tmp/d20151103-24541-ityp8y	0.003s
PASS
ok  	_/tmp/d20151103-24541-ityp8y	0.003s
PASS
ok  	_/tmp/d20151103-24541-ityp8y	0.003s
PASS
ok  	_/tmp/d20151103-24541-ityp8y	0.003s
PASS
ok  	_/tmp/d20151103-24541-ityp8y	0.003s
PASS
ok  	_/tmp/d20151103-24541-ityp8y	0.003s

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

Андрея обнови решението на 03.11.2015 01:38 (преди над 2 години)

+package main
+
+import "strings"
+
+func ExtractColumn(logContents string, column uint8) (result string) {
+ lines := strings.Split(logContents, "\n")
+ lineLength := len(lines)
+
+ var getContent func(s string) string
+ switch {
+ case column == 0:
+ getContent = func(s string) string { return s[:19] }
+ case column == 1:
+ getContent = func(s string) string {
+ subs := s[20:len(s)]
+ subs = subs[:strings.Index(subs, " ")]
+ return subs
+ }
+ case column == 2:
+ getContent = func(s string) string {
+ subs := s[20:len(s)]
+ subs = subs[strings.Index(subs, " ")+1 : len(subs)]
+ return subs
+ }
+ }
+
+ for i := 0; i < lineLength; i++ {
+ if lines[i] != "" {
+ result += getContent(lines[i]) + "\n"
+ }
+ }
+
+ return
+}