程序代码:
#include <stdio.h>
#include <string.h>
void divInt( char *s , int m )
{
int i , j , k , t , lens = strlen( s ) ;
t = k = 0 ;
for( i = 0 ; i < lens ; ++i )
{
t = t * 10 + s[i] - '0' ;
if( t >= m )
{
s[i] = t / m + '0' ;
t %= m ;
}
else
s[i] = '0' ;
}
i = j = 0 ;
while( s[i] == '0' ) i++ ;
while( ( s[j] = s[i] ) != '\0' )
{
i++ ;
j++ ;
}
}
int main()
{
char a[1001] , b[1001] ;
int suma , sumb , len ;
while( ~scanf("%s%s", a , b ) )
{
suma = sumb = 0 ;
while( ( len = strlen( a ) ) != 0 )
{
if( ( a[len-1] - '0' ) % 2 == 1 )
suma++ ;
divInt( a , 2 ) ;
}
while( ( len = strlen( b ) ) != 0 )
{
if( ( b[len-1] - '0' ) % 2 == 1 )
sumb++ ;
divInt( b , 2 ) ;
}
if( suma > sumb )
printf("wm\n") ;
else if( suma == sumb )
printf("neither\n") ;
else printf("zyf\n") ;
}
return 0 ;
}
查查runtime error:
1.buffer overflow --- usually caused by a pointer reference out of range.
2.stack overflow --- please keep in mind that the default stack size is 8192K(Notice: In GCC a little overflow will not get a Runtime Error).
3.illegal file access --- file operations are forbidden on our judge system.
素数环的:
程序代码:
#include <stdio.h>
#include <string.h>
#include <math.h>
int vis[21] ;
int res[21] ;
int n ;
int is_prime( int x )
{
int i ;
for( i = 2 ; i <= (int)( sqrt( x ) + 0.01 ) ; ++i )
{
if( x % i == 0 )
return 0 ;
}
return 1 ;
}
void find_set( int cur )
{
int i ;
if( cur == n )
{
if( is_prime( res[0] + res[cur-1] ) )
{
for( i = 0 ; i < cur ; ++i )
{
printf("%d", res[i] ) ;
if( i != cur - 1 )
printf(" ") ;
}
printf("\n") ;
}
}
for( i = 2 ; i <= n ; ++i )
{
if( !vis[i] && is_prime( i + res[cur-1] ) )
{
vis[i] = 1 ;
res[cur] = i ;
find_set( cur + 1 ) ;
vis[i] = 0 ;
}
}
}
int main()
{
int cur = 0 ;
while( ~scanf("%d", &n ) )
{
memset( vis , 0 , sizeof( vis ) ) ;
cur++ ;
vis[0] = res[0] = 1 ;
printf("Case %d:\n", cur ) ;
find_set( 1 ) ;
printf("\n") ;
}
return 0 ;
}
[
本帖最后由 『点点滴滴』 于 2011-11-21 20:38 编辑 ]