Решение на Разлика в сумите от Иван Иванов

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

Към профила на Иван Иванов

Резултати

  • 9 точки от тестове
  • 0 бонус точки
  • 9 точки общо
  • 14 успешни тест(а)
  • 1 неуспешни тест(а)

Код

package main
import (
"strings"
)
func ExtractColumn(logContents string, column uint8) string {
logContents = strings.TrimLeft(logContents, "\n")
logContents = strings.TrimRight(logContents, "\n")
logContents = strings.TrimLeft(logContents, " ")
logContents = strings.TrimRight(logContents, " ")
logContents = strings.TrimLeft(logContents, " ")
logContents = strings.TrimRight(logContents, " ")
if logContents == "" {
return ""
} else {
var rows []string = strings.Split(logContents, "\n")
return GetLogColumn(rows, column)
}
}
func GetLogColumn(rows []string, column uint8) string {
var result string
switch column {
case 0:
for i := 0; i < len(rows); i++ {
var currentRow string = rows[i]
var currentRowChunks []string = strings.Split(currentRow, " ")
var zeroColumn string = strings.Join(currentRowChunks[0:2], " ")
result = strings.TrimLeft(result+"\n"+zeroColumn, "\n")
}
case 1:
for i := 0; i < len(rows); i++ {
var currentRow string = rows[i]
var currentRowChunks []string = strings.Split(currentRow, " ")
var firstColumn string = strings.Join(currentRowChunks[2:3], " ")
result = strings.TrimLeft(result+"\n"+firstColumn, "\n")
}
case 2:
for i := 0; i < len(rows); i++ {
var currentRow string = rows[i]
var currentRowChunks []string = strings.Split(currentRow, " ")
var currentRowChunksLength = len(currentRowChunks)
var secondColumn string = strings.Join(currentRowChunks[3:currentRowChunksLength], " ")
result = strings.TrimLeft(result+"\n"+secondColumn, "\n")
}
}
return result + "\n"
}

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

PASS
ok  	_/tmp/d20151103-24541-y0rmtd	0.003s
PASS
ok  	_/tmp/d20151103-24541-y0rmtd	0.003s
PASS
ok  	_/tmp/d20151103-24541-y0rmtd	0.003s
PASS
ok  	_/tmp/d20151103-24541-y0rmtd	0.003s
--- FAIL: TestSpacesAtTheStartOrEndOfALine (0.00s)
	solution_test.go:260: Expected
		---
		As far as we can tell this is a DNS
		Yet another DNS, how quaint!
		There is definitely some trend here
		 Some spaces at the beginning of this line
		Nothing particularly interesting happened 
		
		---
		but found
		---
		As far as we can tell this is a DNS
		Yet another DNS, how quaint!
		There is definitely some trend here
		 Some spaces at the beginning of this line
		Nothing particularly interesting happened
		
		---
FAIL
exit status 1
FAIL	_/tmp/d20151103-24541-y0rmtd	0.003s
PASS
ok  	_/tmp/d20151103-24541-y0rmtd	0.003s
PASS
ok  	_/tmp/d20151103-24541-y0rmtd	0.003s
PASS
ok  	_/tmp/d20151103-24541-y0rmtd	0.003s
PASS
ok  	_/tmp/d20151103-24541-y0rmtd	0.003s
PASS
ok  	_/tmp/d20151103-24541-y0rmtd	0.003s
PASS
ok  	_/tmp/d20151103-24541-y0rmtd	0.003s
PASS
ok  	_/tmp/d20151103-24541-y0rmtd	0.003s
PASS
ok  	_/tmp/d20151103-24541-y0rmtd	0.003s
PASS
ok  	_/tmp/d20151103-24541-y0rmtd	0.003s
PASS
ok  	_/tmp/d20151103-24541-y0rmtd	0.003s

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

Иван обнови решението на 25.10.2015 03:56 (преди над 2 години)

+package main
+
+import (
+ "strings"
+)
+
+func ExtractColumn(logContents string, column uint8) string {
+ logContents = strings.TrimLeft(logContents, "\n")
+ logContents = strings.TrimRight(logContents, "\n")
+ logContents = strings.TrimLeft(logContents, " ")
+ logContents = strings.TrimRight(logContents, " ")
+ logContents = strings.TrimLeft(logContents, " ")
+ logContents = strings.TrimRight(logContents, " ")
+
+ if logContents == "" {
+ return ""
+ } else {
+ var rows []string = strings.Split(logContents, "\n")
+ return GetLogColumn(rows, column)
+ }
+}
+
+func GetLogColumn(rows []string, column uint8) string {
+ var result string
+
+ switch column {
+ case 0:
+ for i := 0; i < len(rows); i++ {
+ var currentRow string = rows[i]
+ var currentRowChunks []string = strings.Split(currentRow, " ")
+ var zeroColumn string = strings.Join(currentRowChunks[0:2], " ")
+
+ result = strings.TrimLeft(result+"\n"+zeroColumn, "\n")
+ }
+ case 1:
+ for i := 0; i < len(rows); i++ {
+ var currentRow string = rows[i]
+ var currentRowChunks []string = strings.Split(currentRow, " ")
+ var firstColumn string = strings.Join(currentRowChunks[2:3], " ")
+
+ result = strings.TrimLeft(result+"\n"+firstColumn, "\n")
+ }
+ case 2:
+ for i := 0; i < len(rows); i++ {
+ var currentRow string = rows[i]
+ var currentRowChunks []string = strings.Split(currentRow, " ")
+ var currentRowChunksLength = len(currentRowChunks)
+ var secondColumn string = strings.Join(currentRowChunks[3:currentRowChunksLength], " ")
+
+ result = strings.TrimLeft(result+"\n"+secondColumn, "\n")
+ }
+ }
+
+ return result + "\n"
+}