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

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

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

Резултати

  • 8 точки от тестове
  • 0 бонус точки
  • 8 точки общо
  • 12 успешни тест(а)
  • 3 неуспешни тест(а)

Код

package main
import (
"strings"
)
func ExtractColumn(logContents string, column uint8) string {
logs := strings.SplitAfter(logContents, "\n")
result := ""
for i := 0; i < len(logs); i++ {
if len(logs[i]) > 1 {
result = result + ExtractColumnHelper(logs[i], column)
}
}
return result
}
func ExtractColumnHelper(logContents string, column uint8) string {
buffer := strings.Split(logContents, " ")
line := ""
if column == 0 {
line = line + buffer[0] + " " + buffer[1] + "\n"
} else if column == 1 {
line = buffer[2] + "\n"
} else {
line = buffer[3]
for i := 4; i < len(buffer); i++ {
line = line + " " + buffer[i]
}
}
return line
}

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

PASS
ok  	_/tmp/d20151103-24541-1q0sxlc	0.003s
PASS
ok  	_/tmp/d20151103-24541-1q0sxlc	0.003s
PASS
ok  	_/tmp/d20151103-24541-1q0sxlc	0.003s
PASS
ok  	_/tmp/d20151103-24541-1q0sxlc	0.004s
--- 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-1q0sxlc	0.003s
--- FAIL: TestNoNewLineAtEndOfInput (0.00s)
	solution_test.go:260: Expected
		---
		As far as we can tell this is a DNS
		There is definitely some trend here
		
		---
		but found
		---
		As far as we can tell this is a DNS
		There is definitely some trend here
		---
FAIL
exit status 1
FAIL	_/tmp/d20151103-24541-1q0sxlc	0.004s
PASS
ok  	_/tmp/d20151103-24541-1q0sxlc	0.003s
PASS
ok  	_/tmp/d20151103-24541-1q0sxlc	0.003s
PASS
ok  	_/tmp/d20151103-24541-1q0sxlc	0.003s
PASS
ok  	_/tmp/d20151103-24541-1q0sxlc	0.003s
PASS
ok  	_/tmp/d20151103-24541-1q0sxlc	0.003s
PASS
ok  	_/tmp/d20151103-24541-1q0sxlc	0.003s
PASS
ok  	_/tmp/d20151103-24541-1q0sxlc	0.003s
--- FAIL: TestWithSpaces (0.00s)
	solution_test.go:260: Expected
		---
		spaces   tabs		end
		
		---
		but found
		---
		spaces   tabs		end
		---
FAIL
exit status 1
FAIL	_/tmp/d20151103-24541-1q0sxlc	0.003s
PASS
ok  	_/tmp/d20151103-24541-1q0sxlc	0.004s

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

Стоян обнови решението на 30.10.2015 00:42 (преди над 2 години)

+package main
+
+import (
+ "fmt"
+ "strings"
+)
+
+func ExtractColumn(logContents string, column uint8) string{
+ logs := strings.SplitAfter(logContents, "\n")
+ result := ""
+ for i :=0; i < len(logs); i++ {
+ if ( len(logs[i]) >1){
+ result = result + ExtractColumnHelper(logs[i], column) + "\n"
+ }
+ }
+ return result
+}
+
+func ExtractColumnHelper(logContents string, column uint8) string {
+ buffer := strings.Split(logContents, " ")
+ size := 0
+ i := 0
+ str := ""
+ if column == 0{
+ size = 2
+ i = 0
+ } else if column == 1 {
+ size = 3
+ i = 2
+ }else {
+ i =3
+ size = len(buffer)
+ }
+ for ; i < size; i++ {
+ str = str + buffer[i]
+ }
+ return str
+}
+func main() {
+ fmt.Printf("Hello World\n")
+
+}

Стоян обнови решението на 30.10.2015 12:58 (преди над 2 години)

package main
import (
"fmt"
"strings"
)
func ExtractColumn(logContents string, column uint8) string{
logs := strings.SplitAfter(logContents, "\n")
result := ""
for i :=0; i < len(logs); i++ {
if ( len(logs[i]) >1){
- result = result + ExtractColumnHelper(logs[i], column) + "\n"
+ result = result + ExtractColumnHelper(logs[i], column)
}
}
return result
}
func ExtractColumnHelper(logContents string, column uint8) string {
buffer := strings.Split(logContents, " ")
- size := 0
- i := 0
- str := ""
- if column == 0{
- size = 2
- i = 0
+ line := ""
+ if column == 0 {
+ line = line + buffer[0] + " " + buffer[1] + "\n"
} else if column == 1 {
- size = 3
- i = 2
- }else {
- i =3
- size = len(buffer)
- }
- for ; i < size; i++ {
- str = str + buffer[i]
- }
- return str
+ line = buffer[2] + "\n"
+ } else {
+ line = buffer[3]
+ for i:= 4; i < len(buffer); i++ {
+ line = line + " " + buffer[i]
+ }
+ }
+ return line
}
func main() {
fmt.Printf("Hello World\n")
}

Стоян обнови решението на 02.11.2015 19:07 (преди над 2 години)

package main
import (
- "fmt"
"strings"
)
-func ExtractColumn(logContents string, column uint8) string{
+func ExtractColumn(logContents string, column uint8) string {
logs := strings.SplitAfter(logContents, "\n")
result := ""
- for i :=0; i < len(logs); i++ {
- if ( len(logs[i]) >1){
- result = result + ExtractColumnHelper(logs[i], column)
+ for i := 0; i < len(logs); i++ {
+ if len(logs[i]) > 1 {
+ result = result + ExtractColumnHelper(logs[i], column)
}
}
return result
}
func ExtractColumnHelper(logContents string, column uint8) string {
buffer := strings.Split(logContents, " ")
line := ""
if column == 0 {
line = line + buffer[0] + " " + buffer[1] + "\n"
} else if column == 1 {
line = buffer[2] + "\n"
} else {
line = buffer[3]
- for i:= 4; i < len(buffer); i++ {
+ for i := 4; i < len(buffer); i++ {
line = line + " " + buffer[i]
}
}
return line
}
-func main() {
- fmt.Printf("Hello World\n")
-
-}

Проблема беше заради main-а ли? Махна го сега. Пускам тестовте и пише pass ( пускам вашия и тези от форума). Ако има проблем някъде може ли да кажете? Да го поправя когато има още време.