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 tcxgsy at 2005-08-05 08:44:19 on Problem 2453
In Reply To:有时间 帮帮忙 看看程序中的算法是否可以简化 附有源代码 Posted by:tcxgsy at 2005-08-05 08:33:29
> #include"stdio.h"
> #include"math.h"
> long int progress(long int n)
> { int c,b=0,d=0;
>    while(n!=0)
>      {c=n%2;n/=2;b+=c;}  //将其化为二进制
>     while(d!=b)
>       {  while(++n!=0)
>             {c=n%2;n/=2;d+=c;}  //找其与它相邻的二进制
>        }   
>    return(n);
> }
> main()
> {int i=1,n,b;
>  long int a[1001];
>     scanf("%ld",&a[1]);
>      while(a[i]!=0)
>        {i++;
>          scanf("%ld",&a[i]);  //输入起数据
>         }
>       n=i;
>   for(i=1;i<n;i++)
>       {  b=progress(a[i]); // 调用函数
>           printf("%ld\n",b);
>        }
> }  
> 

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