楼主: Fanyare
跳转到指定楼层
上一主题 下一主题
收起左侧

[CareerCup] [第二轮] 2/18-2/24 CareerCup 1.4

🔗
moophis 2013-2-22 10:55:19 | 只看该作者
全局:
Kimurate 发表于 2013-2-20 10:43
Just copy the char array to a new array and make some change in process.
C language: https://gist.g ...

Your code doesn't work.
There is a compiling error reported by mingw(gcc 3.4.5), in line 40, you should change your code into:
char *replaceStr = (char*) malloc(sizeof(char)*(strlen(str)+countSpace*2));

And output is not correct, either....you should add:
replaceStr[j] = '\0';
at the final stage of your code.
回复

使用道具 举报

🔗
Kimurate 2013-2-22 11:08:04 | 只看该作者
全局:
moophis 发表于 2013-2-22 10:55
Your code doesn't work.
There is a compiling error reported by mingw(gcc 3.4.5), in line 40, you  ...

Thx for advice.
The code worked well on my machine, it should be a problem of the gcc version, which is 4.7 or llvm-gcc-4.2.
I modify my code as your advice, thx again.
回复

使用道具 举报

🔗
champoier 2013-2-23 02:33:43 | 只看该作者
全局:
先找到从最右边开始第一个不是空格的位置i,然后再用一个变量j从最后一个位置开始扫,
如果str是空格,str[j-2..j]替换成"%20"
直到i =j,说明空格填满

https://gist.github.com/skxie/b9d8d368eaa1b6fbdf93
回复

使用道具 举报

🔗
ThunderXu 2013-2-23 10:34:30 | 只看该作者
全局:
https://gist.github.com/ThunderXu/5018072
先算出替换空格后string的结束位置,再从此结束位置开始由后向前的进行再填充,中途遇到空格则依次填充'0''2''%'
回复

使用道具 举报

🔗
willians512 2013-2-24 07:06:17 | 只看该作者
全局:
https://gist.github.com/bigteeth/5021750

算法不知道为什么  后面多存储了一些字符  
回复

使用道具 举报

🔗
sunnyroom 2013-2-24 14:44:10 | 只看该作者
全局:
It is kind of late

overveiw'

1 calculate new lengh
2 replace spaces with %20
https://gist.github.com/sunxw/5022902
回复

使用道具 举报

🔗
qiaobao 2013-2-25 07:06:56 | 只看该作者
全局:
1. count the total number of space in the string.
2. subtract the spaces at the beginning and at the end.
3. create a new string to store output string
4. copy output string to input string

https://gist.github.com/Andy1989/69f32cc3ea90c34e7cd8
回复

使用道具 举报

🔗
yzl232 2013-2-26 11:07:22 | 只看该作者
全局:
https://gist.github.com/yzl232/5035524

用python。 还简单。


回复

使用道具 举报

🔗
cjsp 2013-2-28 20:15:15 | 只看该作者
全局:
https://gist.github.com/flatlight/5056328
first calculate the length, then replace backwards in order to replace in place
回复

使用道具 举报

🔗
cjsp 2013-2-28 20:16:37 | 只看该作者
全局:
yzl232 发表于 2013-2-26 11:07
https://gist.github.com/yzl232/5035524

用python。 还简单。

原题的意思应该是做in place的替换..即空间复杂度是O(1)才对..
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表