#include <stdafx.h>
#include <string.h>
#include <stdio.h>
#define MAXLEN 1024
int main()
{
char pStrInput[MAXLEN];
char *pStr1 = "%20";
//scanf("%s", pStrInput);
char ch;
int i;
for(i = 0; i < MAXLEN && (ch = getchar()) != '\n'; i++)
{
pStrInput[i] = ch;
}
pStrInput[i] = 0;
int iStrLen = strlen(pStrInput);
int iNumSpace = 0;
int iNewLen = 0;
for(int i = 0; i < iStrLen; i++)
{
if(pStrInput[i] == ' ')
iNumSpace++;
}
iNewLen = (strlen(pStr1) - 1) * iNumSpace + iStrLen;
pStrInput[iNewLen] = 0;
int j = iNewLen - 1;
int k = 0;
for(i = iStrLen - 1; i >= 0; i--)
{
if(pStrInput[i] == ' ')
{
for(k = strlen(pStr1) - 1; k >= 0; k--)
pStrInput[j--] = pStr1[k];
}
else
pStrInput[j--] = pStrInput[i];
}
printf("The new string is %s\n", pStrInput);
return 0;
}
cracking the coding interview problem solution 1.5
原创
©著作权归作者所有:来自51CTO博客作者nicolin7的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Python Coding Interview
Python Coding InterviewPython AdvancedJupyterJupyter Notebook
Jupyter Notebook Jupyter Coding Interview Advanced Python

















