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:有时间 帮帮忙 看看程序中的算法是否可以简化 附有源代码In Reply To:Re:有时间 帮帮忙 看看程序中的算法是否可以简化 附有源代码 Posted by:tcxgsy at 2005-08-05 09:00:41 #include"stdio.h" #include"math.h" long int progress(long int n) { int c,b=0,d=0; long int m=n; while(n!=0) {c=n%2;n/=2;b+=c;} while(d!=b) { while(++m!=0) {c=m%2;m/=2;d+=c;} } return(m); } 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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator