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

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

🔗
moophis 2013-2-18 17:17:46 | 只看该作者
全局:
https://github.com/moophis/careercup/blob/master/1.4.cpp
First scan through the string while counting spaces between words and drop redundant spaces at the end of the string. Then relocate the pointer to the end of the new extended string.
Then move the string to the new place, replacing each space with "%20".
回复

使用道具 举报

全局:
I don't know if I got it right. I pass a string and it's true length in to the method. Change the string to char array and use a for loop to replace the spaces and copy the none-space letters.

https://gist.github.com/lynntian/4981097
回复

使用道具 举报

🔗
EchoMemory 2013-2-19 13:18:48 | 只看该作者
全局:
s = s.replace(' ', '%20')
回复

使用道具 举报

🔗
jerrysun 2013-2-20 00:26:18 | 只看该作者
全局:
https://github.com/JerrySun363/C ... /ReplaceString.java

First scan the string, count the number of spaces,
then start backwards to put the the k th character between the i th and (i+1)th space to the place of (k+i * 2) character.
Start from the end to make sure "in place" since no need of extra memory allocation.
+++++++++++++
ls 的解答过于简单了吧,直接调用函数似乎不是这道题的点吧... ...

点评

看来大家的想法都是一样的,有木有其他solution?  发表于 2013-2-20 10:52
回复

使用道具 举报

🔗
Kimurate 2013-2-20 10:43:31 | 只看该作者
全局:
Just copy the char array to a new array and make some change in process.
C language: https://gist.github.com/hukun01/4992287
very simple, kind of stupid.
回复

使用道具 举报

🔗
liuzhe1218 2013-2-20 11:30:29 | 只看该作者
全局:
本帖最后由 liuzhe1218 于 2013-2-20 12:02 编辑

Java language:
https://gist.github.com/mettaworld/4992621
In order not to use the function replace directly, I make a stupid algorithm to count the number and index of spaces, and then output the chars into a new array.
回复

使用道具 举报

🔗
rialmat 2013-2-20 18:32:37 | 只看该作者
全局:
Use C++
First off, find the last non-space character in the string.
Then start from that position and scan the string backwards. When encounter a space, replace it with "%20"
Finally, cut off the last 2*numOfSpaces characters of the string.
https://gist.github.com/rischimart/4994109#file-cc1_4-cpp
回复

使用道具 举报

🔗
lazyGoose 2013-2-21 03:05:37 | 只看该作者
全局:
1. New a "new char array".
2. Get a char in "input" one by one and put them into "new char array"
3. put a '\0' to the end of the "new char array"

https://gist.github.com/lazyGoose/26453c19a2544461c0d3
回复

使用道具 举报

🔗
 楼主| Fanyare 2013-2-21 08:31:08 | 只看该作者
回复

使用道具 举报

🔗
SunnyDay1022 2013-2-21 12:51:51 | 只看该作者
全局:
idea is similar to split the string by whitespace
create new string
find whitespace from the begin of original string, put all characters from "begin" to whitespace(exclude whitespace) in new string
add an '%20' instead of whitespace, set the one next to current found whitespace as the new "begin", repeat
Note: get rid of replacing the whitespace after the real content's end
https://github.com/swang1022/car ... .4/spaceReplace.cpp

I'm a little confused about what the "'true' length" means in the question, does anyone have an idea?
回复

使用道具 举报

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

本版积分规则

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