天天好味道
没钱没权没户口,靠走靠吼靠小狗
随笔 - 66, 文章 - 1, 评论 - 524, 引用 - 5
导航
VC知识库BLOG
首页
新随笔
联系
登录
<
2007年2月
>
日
一
二
三
四
五
六
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
1
2
3
4
5
6
7
8
9
10
留言簿(12)
给我留言
查看公开留言
查看私人留言
随笔分类
智能手机软件开发 (6)
(rss)
Web开发 (2)
(rss)
Lua (4)
(rss)
智力游戏 (2)
(rss)
Python&Toy (10)
(rss)
软件设计 (25)
(rss)
随笔档案
2008年1月 (1)
2007年10月 (2)
2007年9月 (1)
2007年8月 (1)
2007年7月 (6)
2007年6月 (3)
2007年5月 (4)
2007年2月 (3)
2007年1月 (3)
2006年12月 (2)
2006年11月 (4)
2006年10月 (1)
2006年9月 (1)
2006年8月 (8)
2006年7月 (9)
2006年6月 (2)
2006年5月 (6)
2006年4月 (4)
2006年3月 (5)
文章档案
2006年6月 (1)
我的链接
lostpencil
我的主页
搜索
最新评论
1. www.clshoe.com
--clshoe
2. www.eurluxury.com
Hi friend: Let you excited place!
We conduct: <a href=www.eurluxury.com>Christian Louboutin</a>
will read the first time, thank!
--eurluxury
3. www.eurluxury.com
Hi friend: Let you excited place!
We conduct: <a href=www.eurluxury.com>Christian Louboutin</a>
will read the first time, thank!
--eurluxury
4. re: [S60] ARM平台独有问题 Writable Static Data in DLLs
S60的官方解释更是漏洞颇多,说增加可写的全局变量每一个DLL被引用的时候会增加4K内存使用,当DLL被很多程序引用的时候会消耗很多内存,所以就不让用了。你自己做DLL当然要注意,实际上用户的APP程序只有自己使用,凭什么不让用了?
--sleepsaint
5. re: lampp基础上增加mod_cband控制速度和连接数
[url=
http://www.friendtrans.com/
]翻译公司[/url]
<a href="
http://www.zslh.com/">汽车模拟驾驶器</a>
--xczxc
6. re: 五行写一个atoi
[url=
http://www.friendtrans.com/
]翻译公司[/url]
<a href="
http://www.zslh.com/">汽车模拟驾驶器</a>
--xczxc
7. re: 开始阅读Lua的源代码
正好用得
--今天
8. re: TCL/Python/Lua for WinCE
lz的tcl移植版是在哪里下载的,我也想要
--chentan
9. www.ptsell.com
--ptsell
10. www.ant-shopping.com
--ant-shopping
阅读排行榜
1. 一段Python程序和C程序的对比(12637)
2. Python绝对是最有前途的脚本语言! - 看到Python for S60有感(3603)
3. 五行写一个atoi(3465)
4. [S60] ARM平台独有问题 Writable Static Data in DLLs(3233)
5. 郁闷的ACE for WinCE(3196)
6. PDF 文件格式描述(3095)
7. 一道高中物理题,蛮有意思的。还记得高中物理的可以看看:)(3064)
8. Lua 真是太帅了!(3047)
9. 抽象工厂模式的好处-to 晓寒(2925)
10. 另一个Python和C程序的对比(2665)
评论排行榜
1. 一段Python程序和C程序的对比(166)
2. Python绝对是最有前途的脚本语言! - 看到Python for S60有感(18)
3. [S60] ARM平台独有问题 Writable Static Data in DLLs(16)
4. 再次崇拜C(16)
5. 郁闷的ACE for WinCE(15)
6. 正如java在企业开发领域推倒C++一样。脚本或称为动态语言成为主流的时刻不远了(14)
7. 刚开始学习Web 开发的MVC模式 - CakePHP(13)
8. 五行写一个atoi(13)
9. 想不到VIM竟然这么好用(13)
10. 一道高中物理题,蛮有意思的。还记得高中物理的可以看看:)(12)
五行写一个atoi
偶然看到的一道题目,要求输入一个字符串指针,输出这个字符串转换成数值的结果。也就是atoi。
不过题目有个奇怪的要求,函数体少于五行。虽然C可以把所有的代码写到一行,不过估计题目的
意思是希望算法简练吧。还要求有必要的错误处理。如果要考虑正负号,非法字符,空格还是挺麻烦的。
posted on 2007-02-09 16:19 jzhang 阅读(3465)
评论(13)
编辑
收藏
评论
#
re: 五行写一个atoi
int cint(char *arr){
int flag = (*arr == '-' ? ++arr, 1 : 0), result = 0;
while (*arr != '\0' && *arr >= '0' && *arr <= '9') result = result * 10 + *arr++ - '0';
return flag ? ~result : result;
}
抛块砖,引点玉……
2007-02-09 16:43 |
林杰杰
#
C/C++程序就这德行呀
记得国际上有一个比赛,以程序写得隐晦为目标,最让人看不懂的程序可以得大奖,没有指定编程语言,但提交的作品几乎都是C或C++。
这是C的个性,也是C的悲哀。
2007-02-09 17:49 |
linkman
#
re 林杰杰:
既然你判断*arr == '-',那么'+也应该判断。
*arr != '\0' 似乎是多余的,你觉得呢?
~result 应当是 -result ,笔误 ^_^
2007-02-10 14:48 |
周星星
#
re: 五行写一个atoi
周星星同学说得没错,真是细心。 ^_^值得学习。
2007-02-10 19:43 |
林杰杰
#
re: 五行写一个atoi
...要晦涩..那不是很简单麻..写点缓冲区,利用缓冲溢出,在程序里用反汇编出来的机器码做事....不通过其他工具想要看懂..这是人类能做到的事嘛...
2007-08-14 03:19 |
Dustman
#
re: 五行写一个atoi
int atoi(char *msg)
{
while((*msg&&*msg==' ')||(*msg&&*msg=='+')){msg++;}
.....
}
5行实在没办法搞定
2007-08-14 03:24 |
~~
#
re: 五行写一个atoi
long atoi(char *arr)
{
long flag = 0, result = 0;
while(*arr == ' ') arr++;
flag = ((*arr == '-') ? ++arr, 1 : (*arr == '+' ? ++arr, 0 : 0));
while (*arr >= '0' && *arr <= '9') result = result * 10 + (*arr++ - '0');
return flag ? -result : result;
}
算5行不?
2007-10-09 17:36 |
lm
#
re: 五行写一个atoi
我写了一个四行的函数,大家看看有问题不
int myatoi(char *s)
{
int ret = (*s == '-' || *s == '+')? (',' - (*s)) * (*(++s) - '0'): *s - '0';
while((*(++s) >= '0') && (*s <= '9'))
ret = (ret >= 0)? ret * 10 + (*s - '0'): ret * 10 + ('0' - *s);
return ret;
}
如果按照分号来算行数,其实是3行 :-)
用了一个ascii字符的特性 ',' - '+' == 1 ',' - '-' == -1
2007-10-15 21:18 |
TripleX
#
re: 五行写一个atoi
TripleX,你的函数在输入字符如“+sda”的情况下就会错误执行。
原因在(*(++s) - '0'): 处的自增操作。
2007-11-19 15:08 |
lm
#
www.ptsell.com
I support author's viewpoint, hoped that will have later also more better articles,
[url=
http://www.ptsell.com
">
http://www.ptsell.com
]Chanel[/url]
[url=
http://www.ptsell.com
">
http://www.ptsell.com
]Gucci[/url]
will read the first time, thank!
2008-10-17 16:19 |
ptsell
#
www.ant-shopping.com
I support author's viewpoint, hoped that will have later also more better articles,
<a href=
http://www.ant-shopping.com/nike-shoes.html>nike
shoes</a>
<a href=
http://www.ant-shopping.com/juicy-couture.html>juicy
couture</a>
will read the first time, thank!
2008-10-17 16:19 |
ant-shopping
#
re: 五行写一个atoi
[url=
http://www.friendtrans.com/
]翻译公司[/url]
<a href="
http://www.zslh.com/">汽车模拟驾驶器</a>
2008-11-05 11:29 |
xczxc
#
www.eurluxury.com
Hi friend: Let you excited place!
We conduct: <a href=www.eurluxury.com>Christian Louboutin</a>
will read the first time, thank!
2008-11-13 10:39 |
eurluxury
标题
姓名
主页
验证码
*
内容
Remember Me?
登录
使用高级评论
Top
[使用Ctrl+Enter键可以直接提交]
Powered by:
Copyright © jzhang