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:我这代码哪里可以优化?

Posted by fangxubz at 2014-04-21 11:30:09 on Problem 1316
In Reply To:我这代码哪里可以优化? Posted by:haipeng31 at 2010-11-14 20:01:26
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> 
> int digitsum(int num)
> {
> 	int sum = 0;
> 	while(num != 0) {
> 		sum += num % 10;
> 		num = num / 10;
> 	}
> 	return sum;
> }
> 
> int main()
> {
> 	char selfstates[1000101];
> 	int i, j;
> 	int sum;
> 	for(i = 0; i < 1000001; i++)
> 	{
> 		selfstates[i] = 0;
> 	}
> 
> 	for(i = 0; i <= 999990; i += 10)
> 	{
> 		sum = i + digitsum(i);
> 		for(j = 0; j < 10; j++) {
> 			selfstates[sum+2*j] = 1;
> 		}
> 	}
> 
> 	for(i = 1; i <= 1000000; i++)
> 	{
> 		if(selfstates[i] == 0) {
> 			printf("%d\n", i);
> 		}
> 	}
> 
> 	return 0;
> }

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