xfstart07
Get busy living or get busy dying
#include < cstdio >
#include
< cstring >
#include
< cstdlib >
using   namespace  std;

int  N;
int  len;
char  s[ 1010 ],c[ 1010 ];
void  work1()
{
    
int  sum = 0 ;
    
for ( int  i = 0 ;i < N; ++ i)
        
if (s[i] == ' 1 ' )
            sum
+= (i + 1 );
    
if (sum % (N + 1 ) == 0 ){
        printf(
" %s\n " ,s);
        
return ;
    }
    strcpy(c,s);
    
for ( int  i = 0 ;i < len; ++ i){
        
if (s[i] == ' 0 ' continue ;
        c[i]
= ' 0 ' ;
        
if ((sum - (i + 1 )) % (N + 1 ) == 0 ){
            printf(
" %s\n " ,c);
            
return ;
        }
        c[i]
= ' 1 ' ;
    }
}
void  work2()
{
    
for ( int  i = N - 1 ;i >= 0 ; -- i){
        c[i]
= ' 0 ' ;  c[N] = ' \0 ' ;
        
for ( int  j = 0 ;j < i; ++ j) c[j] = s[j];
        
for ( int  j = i;j < len; ++ j) c[j + 1 ] = s[j];
        
int  sum = 0 ;
        
for ( int  j = 0 ;j < N; ++ j)
            
if (c[j] == ' 1 ' ) sum += (j + 1 );
        
if (sum % (N + 1 ) == 0 ){
            printf(
" %s\n " ,c);
            
return ;
        }
        c[i]
= ' 1 ' ;
        
if ((sum + (i + 1 )) % (N + 1 ) == 0 ){
            printf(
" %s\n " ,c);
            
return ;
        }
    }
}
void  work3()
{
    
for ( int  i = len - 1 ;i >= 0 ; -- i){
        
for ( int  j = 0 ;j < i; ++ j)
            c[j]
= s[j];
        
for ( int  j = i;j < len; ++ j)
            c[j]
= s[j + 1 ];
        
int  sum = 0 ;
        c[N]
= ' \0 ' ;
        
for ( int  j = 0 ;j < N; ++ j)
            
if (c[j] == ' 1 ' ) sum += (j + 1 );
        
if (sum % (N + 1 ) == 0 ){
            printf(
" %s\n " ,c);
            
return ;
        }
    }
}
int  main()
{
    freopen(
" 1007.in " , " r " ,stdin);
    freopen(
" 1007.out " , " w " ,stdout);
    scanf(
" %d " , & N);
    
while (scanf( " %s " ,s) != EOF){
        len
= strlen(s);
        
if (len == N) work1();
        
else   if (len < N) work2();
        
else   if (len > N) work3();
    }
    
return   0 ;
}




posted on 2009-07-20 17:12 xfstart07 阅读(181) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理