Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:1002总结In Reply To:1002总结 Posted by:Thrush at 2010-07-26 23:46:56 > int num(char *tel) > { > int i; > int n=0; > > for ( i=0; i<strlen(tel); i++ ) > if ( tel[i]>='0' && tel[i]<='9' ) > n = n * 10 + ( tel[i] - 48 ); > return n; > } > 好像还有改进的地方。 1) strlen会遍历字符串,会耗时。 2) 你前面已经convert,就无需判断是否为digit了 因此可以改为: static int a_to_i(char *arg) { int num = 0; int c; while ((c = *arg++) != '\0') { num = 10 * num + c - '0'; } return num; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator