您的位置:首页 > Web前端

LintCode-剑指Offer-空格替换

2015-11-16 23:43 267 查看
class Solution {

public:

    /**

     * @param string: An array of Char

     * @param length: The true length of the string

     * @return: The true length of new string

     */

    int replaceBlank(char string[], int length) {

        // Write your code here

        char strmy[1000];

        int tmp=0;

        int i;

        for(i=0;i<length;i++)

        {

            strmy[i]=string[i];

        }

        for(i=0;i<length;i++){

            if(strmy[i]==' '){

                string[i+tmp*2]='%';

                string[i+tmp*2+1]='2';

                string[i+tmp*2+2]='0';

                tmp++;

            }else

                string[i+tmp*2]=strmy[i];

        }

        return i+tmp*2;

        

    }

};  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  LintCode