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

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

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

Резултати

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

Код

package main
func ExtractColumn(logContents string, column uint8) string {
var answer = ""
var from = 0
var count = 0
if column == 0 {
for index := 0; index < len(logContents); index++ {
if logContents[index] == ' ' {
count++
}
if count == 2 {
answer += logContents[from:index] + "\n"
count++
}
if logContents[index] == '\n' {
from = index + 1
count = 0
}
}
} else if column == 1 {
for index := 0; index < len(logContents); index++ {
if logContents[index] == ' ' {
count++
}
if count == 2 {
from = index + 1
count++
}
if count == 4 {
answer += logContents[from:index] + "\n"
count++
}
if logContents[index] == '\n' {
count = 0
}
}
} else {
for index := 0; index < len(logContents); index++ {
if logContents[index] == ' ' {
count++
}
if count == 3 {
from = index + 1
count++
}
if logContents[index] == '\n' || index == len(logContents)-1 {
answer += logContents[from : index+1]
if logContents[index] != '\n' {
answer += "\n"
}
count = 0
}
}
}
return answer
}

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

PASS
ok  	_/tmp/d20151103-24541-8dmuib	0.003s
PASS
ok  	_/tmp/d20151103-24541-8dmuib	0.003s
PASS
ok  	_/tmp/d20151103-24541-8dmuib	0.003s
PASS
ok  	_/tmp/d20151103-24541-8dmuib	0.003s
PASS
ok  	_/tmp/d20151103-24541-8dmuib	0.003s
PASS
ok  	_/tmp/d20151103-24541-8dmuib	0.003s
PASS
ok  	_/tmp/d20151103-24541-8dmuib	0.003s
--- FAIL: TestWithOnlyOneNewLine (0.00s)
	solution_test.go:260: Expected
		---
		
		---
		but found
		---
		
		
		---
FAIL
exit status 1
FAIL	_/tmp/d20151103-24541-8dmuib	0.003s
PASS
ok  	_/tmp/d20151103-24541-8dmuib	0.003s
PASS
ok  	_/tmp/d20151103-24541-8dmuib	0.003s
PASS
ok  	_/tmp/d20151103-24541-8dmuib	0.003s
PASS
ok  	_/tmp/d20151103-24541-8dmuib	0.005s
PASS
ok  	_/tmp/d20151103-24541-8dmuib	0.003s
PASS
ok  	_/tmp/d20151103-24541-8dmuib	0.004s
PASS
ok  	_/tmp/d20151103-24541-8dmuib	0.006s

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

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

+package main
+
+func ExtractColumn(logContents string, column uint8) string {
+ var answer = ""
+ var from = 0
+ var count = 0
+
+ if column == 0 {
+ for index := 0; index < len(logContents); index++ {
+ if logContents[index] == ' ' {
+ count++
+ }
+
+ if count == 2 {
+ answer += logContents[from:index] + "\n"
+ count++
+ }
+
+ if logContents[index] == '\n' {
+ from = index + 1
+ count = 0
+ }
+ }
+ } else if column == 1 {
+ for index := 0; index < len(logContents); index++ {
+ if logContents[index] == ' ' {
+ count++
+ }
+
+ if count == 2 {
+ from = index + 1
+ count++
+ }
+
+ if count == 4 {
+ answer += logContents[from:index] + "\n"
+ count++
+ }
+
+ if logContents[index] == '\n' {
+ count = 0
+ }
+ }
+ } else {
+ for index := 0; index < len(logContents); index++ {
+ if logContents[index] == ' ' {
+ count++
+ }
+
+ if count == 3 {
+ from = index + 1
+ count++
+ }
+
+ if logContents[index] == '\n' || index == len(logContents)-1 {
+ answer += logContents[from : index+1]
+
+ if logContents[index] != '\n' {
+ answer += "\n"
+ }
+ count = 0
+ }
+ }
+ }
+
+ return answer
+}