tangs 2 rokov pred
rodič
commit
b13b4c54b2
1 zmenil súbory, kde vykonal 30 pridanie a 0 odobranie
  1. 30 0
      leetcode/剑指offer/替换空格/main.go

+ 30 - 0
leetcode/剑指offer/替换空格/main.go

@@ -0,0 +1,30 @@
+package main
+
+import (
+	"bufio"
+	"fmt"
+	"os"
+)
+
+func main() {
+	input := bufio.NewScanner(os.Stdin)
+	var output string
+	for input.Scan() {
+		line := input.Text()
+
+		output = replaceSpace(line)
+		fmt.Println(output)
+	}
+}
+
+func replaceSpace(s string) string {
+	var last string
+	for _, v := range s {
+		if string(v) == " " {
+			last += "%20"
+			continue
+		}
+		last += string(v)
+	}
+	return last
+}