Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:1002总结

Posted by lhdtigerblue at 2010-08-01 14:39:24 on Problem 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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator