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

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

🔗
sunnyroom 2013-2-19 21:28:51 | 只看该作者
全局:
循环到字符串的一半,交换相应位置的字符。
https://gist.github.com/sunxw/4985867
回复

使用道具 举报

🔗
yukainuo23 2013-2-19 21:43:26 | 只看该作者
全局:
https://gist.github.com/anonymous/4985968

strlen应该把指针从指向地址开始一直数到出现‘\0’为止应该不用再判断什么时候‘\0’什么时候出现了吧!
写java太多换C/C++有一种恐惧感咋办!
回复

使用道具 举报

🔗
SunnyDay1022 2013-2-19 22:39:21 | 只看该作者
全局:
method1: using std::strlen() get the length of char*,loop from begin to len/2-1, swap current i th character with len-1-i th character
method2:  using an new array of char reversedStr, which length is the length of char* str plus 1,  reversely store str to reversedStr, add \0 to the end of new array
https://github.com/swang1022/car ... 01.2/reverseStr.cpp
回复

使用道具 举报

🔗
champoier 2013-2-20 02:01:08 | 只看该作者
全局:
strlen()找到结尾,然后循环swap元素。

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

使用道具 举报

🔗
lazyGoose 2013-2-20 02:10:50 | 只看该作者
全局:
先算长度,再交换...
https://gist.github.com/lazyGoose/4988336
回复

使用道具 举报

🔗
lazyGoose 2013-2-20 02:13:18 | 只看该作者
全局:
champoier 发表于 2013-2-20 02:01
strlen()找到结尾,然后循环swap元素。

https://gist.github.com/skxie/c632e87f9cc24c90cbb3

我是新手,感觉都是学习贴,
swap(E a, E b)可以在C++中直接用, 学习了!
回复

使用道具 举报

🔗
champoier 2013-2-20 02:40:52 | 只看该作者
全局:
lazyGoose 发表于 2013-2-19 13:13
我是新手,感觉都是学习贴,
swap(E a, E b)可以在C++中直接用, 学习了!

用的时候要加头文件<algorithm>和std.
回复

使用道具 举报

🔗
superdry 2013-2-20 07:38:38 | 只看该作者
全局:
https://github.com/knightelvis/a ... eercup/reverseStr.c
simply use two pointers pointing from the beginning and the end separately and swap the values until they meet.
回复

使用道具 举报

全局:
https://github.com/1094401996/Ca ... r1/onedot2/cstyle.c  
好久不写C了。。。。这个参考了答案
回复

使用道具 举报

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

本版积分规则

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