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:大侠门帮我看看吧! 我都wa n+1次了In Reply To:大侠门帮我看看吧! 我都wa n+1次了 Posted by:huanghaoxiang at 2009-07-13 16:39:11 sum=sum*i+s2[k];这个地方不对, 越界!! 改成 for(k=0;k<j;++k) sum=(sum*i+s2[k])%(i-1); if(sum==0) { printf ( "%d\n",i ); break; } 试试看! > #include <stdio.h> > #include <math.h> > > int main() > { > int i,k,j; > char s1[30000]; > int s2[30000]; > while ( scanf ( "%s",s1 ) != EOF ) > { > char *p1 = s1; > int max = 0; > for ( j = 0; *p1 != '\0'; ++p1,++j ) > { > if ( *p1 >= '0' && *p1 <= '9' ) > s2[j] = *p1 - '0'; > else if ( *p1 >= 'A' && *p1 <= 'Z' ) > s2[j] = 10 + (*p1 - 'A'); > else if( *p1 >= 'a' && *p1 <= 'z' ) > s2[j] = 36 + ( *p1 - 'a' ); > if ( s2[j] > max ) > max = s2[j]; > } > long sum; > for ( i = max+1; i <= 62; ++i ) > { > sum = 0; > for ( k = 0; k < j; ++k ) > sum=sum*i+s2[k]; > if ( sum % ( i - 1 ) == 0 ) > { > printf ( "%d\n",i ); > break; > } > } > if ( i > 62 ) > printf ( "such number is impossible!\n" ); > } > return 0; > } > > > Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator