Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

这样也AC了,哈哈,神奇,注意头文件

Posted by allh123 at 2012-08-28 19:29:16 on Problem 1248
#include <stdio.h>

int main()
{
    int target , i, j, k, l, d, g ,re , len, s;
    char b[6] ,a[20] ,sol[1000][6] ,max[6] ;
    b[5] = '0' ;
//    freopen("in.c","r",stdin) ;
//    freopen("out.c","w",stdout) ;
    while(scanf("%d%s",&target,a) != EOF)
    {
      if(target == 0 && strcmp(a,"END") == 0)
        break ;
        re = 0 ;
        len = strlen(a) ;
        for(i = 0 ; i < len ; i++)
        {
          a[i] = a[i] - 64 ;
        }
        for(i = 0 ; i < len ; i++)
        {
          b[0] = a[i] ;
           for(j = 0 ; j < len ; j++)
           {
             if(j == i) continue ;
              b[1] = a[j] ;
              for(k = 0 ; k < len ; k++)
              {
                if(k == i || k == j) continue ;
                 b[2] = a[k] ;
                 for(l = 0 ; l < len ; l++)
                 {
                   if(l == i || l == j || l == k)  continue ;
                   b[3] = a[l] ;
                   for(d = 0 ; d < len ; d++)
                   {
                     if(d == i || d == j || d == k || d == l)  continue ;
                     b[4] = a[d] ;
                     s = 0 ;
                     for ( g = 1 ; g <= 5 ; g++)
                       s += pow(-1,g-1)*pow(b[g-1],g) ;
                       if(s == target)
                       {
                         for(g = 0 ; g < 5 ; g++)
                          sol[re][g] = b[g] + 64 ;
                          re++ ;
                       }
                   }
                 }
              }
           }
        }
        if(re == 0 ) printf("no solution\n") ;
        else
        {
            strcpy(max,sol[0]) ;
            for( i = 1 ; i <re ; i++)
             if(strcmp(sol[i],max) > 0)
                 strcpy(max,sol[i]) ;
                 printf("%s\n",max) ;
        }
    }
    return  0 ;
}


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator