package Part1;

/**
 * Created by matao on 10/15/16.
 *
 * <p>
 * Write a method to replace all spaces in a string with'%20'.
 * You may assume that the string has sufficient space at the end of the string
 * to hold the additional characters,
 * and that you are given the "true" length of the string.
 * (Note: if imple- menting in Java,
 * please use a character array so that you can perform this opera- tion in place.)
 *
 * EXAMPLE
 * Input: "Mr John Smith Output: "Mr%20Dohn%20Smith"
 *
 * 将字符串中的空格全部替换为"%20"，假定该字符串尾部有足够的空间存放新增字符，并且知道字符串的"真实"长度。
 * Java请用字符数字实现。
 */
public class Q4 {
}

@@ -9,16 +9,65 @@
 Part1;%0A%0A
+import org.junit.Assert;%0Aimport org.junit.Test;%0A%0A
 /**%0A * C
@@ -97,16 +97,20 @@
 5/16.%0A *
+ %3Cp%3E
 %0A * %3Cp%3E%0A
@@ -472,16 +472,20 @@
 ace.)%0A *
+ %3Cp%3E
 %0A * EXAM
@@ -512,16 +512,17 @@
 hn Smith
+%22
  Output:
@@ -532,9 +532,9 @@
 r%2520
-D
+J
 ohn%25
@@ -544,16 +544,20 @@
 mith%22%0A *
+ %3Cp%3E
 %0A * %E5%B0%86%E5%AD%97%E7%AC%A6%E4%B8%B2
@@ -574,83 +574,982 @@
 %2520%22
-%EF%BC%8C%E5%81%87%E5%AE%9A%E8%AF%A5%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%B0%BE%E9%83%A8%E6%9C%89%E8%B6%B3%E5%A4%9F%E7%9A%84%E7%A9%BA%E9%97%B4%E5%AD%98%E6%94%BE%E6%96%B0%E5%A2%9E%E5%AD%97%E7%AC%A6%EF%BC%8C%E5%B9%B6%E4%B8%94%E7%9F%A5%E9%81%93%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%9A%84%22%E7%9C%9F%E5%AE%9E%22%E9%95%BF%E5%BA%A6%E3%80%82%0A * Java%E8%AF%B7%E7%94%A8%E5%AD%97%E7%AC%A6%E6%95%B0%E5%AD%97%E5%AE%9E%E7%8E%B0%E3%80%82%0A */%0Apublic class Q4 %7B
+%E3%80%82%0A */%0Apublic class Q4 %7B%0A%0A    /**%0A     * %E7%AC%AC%E4%B8%80%E6%AC%A1%E6%89%AB%E6%8F%8F%E7%A1%AE%E5%AE%9A%E7%A9%BA%E6%A0%BC%E4%B8%AA%E6%95%B0%EF%BC%8C%E4%B8%80%E4%B8%AA%E7%A9%BA%E6%A0%BC%E8%A2%AB%E6%9B%BF%E6%8D%A2%E6%88%90%2520,%0A     * %E6%95%85%E6%AF%8F%E4%B8%AA%E7%A9%BA%E6%A0%BC%E5%A4%9A%E4%B8%A4%E4%B8%AA%E9%95%BF%E5%BA%A6%E3%80%82%0A     * %E5%B0%BE%E9%83%A8%E5%BC%80%E5%A7%8B%E6%89%AB%E6%8F%8F%0A     */%0A    public String replaceSpace(String s) %7B%0A        int spaceCount = 0;%0A        int newLength;%0A        char%5B%5D chars = s.toCharArray();%0A        for (char c : chars) %7B%0A            if (c == ' ') %7B%0A                spaceCount++;%0A            %7D%0A        %7D%0A        newLength = chars.length + 2 * spaceCount;%0A        char%5B%5D newChars = new char%5BnewLength%5D;%0A%0A        int i = chars.length - 1;%0A        int j = newLength - 1;%0A        while (i %3E= 0) %7B%0A            if (chars%5Bi%5D == ' ') %7B%0A                i--;%0A                newChars%5Bj--%5D = '0';%0A                newChars%5Bj--%5D = '2';%0A                newChars%5Bj--%5D = '%25';%0A            %7D else %7B%0A                newChars%5Bj--%5D = chars%5Bi--%5D;%0A            %7D%0A        %7D%0A        return new String(newChars);%0A    %7D%0A%0A    @Test%0A    public void testReplaceSpace() %7B%0A        Assert.assertEquals(%22Mr%2520John%2520Smith%22, replaceSpace(%22Mr John Smith%22));%0A    %7D
 %0A%7D%0A

Revise solution of 1-4