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 |
谁能帮帮我,为什么过不了?我在VC上运行都通过了啊!#include <iostream.h> #include <math.h> int main() { void digitroot(unsigned long a[] , unsigned long); unsigned long digit(unsigned long a[] , unsigned long); unsigned long a[100000]; unsigned long N; while( cin >> N && N) { digitroot(a , digit(a,N)); cout << a[0] <<endl; } return 0; } unsigned long digit(unsigned long a[] , unsigned long N) { unsigned long m; unsigned long x=N; m = (unsigned long)log10(N); for(unsigned long i=0 ; i<= m ; i++) { a[i]=x%10; x/=10; } return m; } void digitroot(unsigned long a[] , unsigned long m ) { if(m==0); else { unsigned long sum=0; for(unsigned long i=0 ; i <= m ; i++) sum+=a[i]; digitroot(a , digit(a,sum)); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator