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

Re:WA WA WA 为什么一直都是WA !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Posted by houxuanfelix at 2006-06-14 23:06:59 on Problem 2718
In Reply To:WA WA WA 为什么一直都是WA !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Posted by:houxuanfelix at 2006-06-10 23:31:23
> 这是我的程序,大牛帮忙看一下吧!我实在不知道哪个地方错了
> #include <stdio.h>
> #include <string.h>
> 
> int  abs(int m)
> {
>      if (m>=0)   return m;
>      else        return -m;
> }
>  
> int  main()
> {
>      int   i,j,k,n,a,b,t,ts,num[11],min,flag;
>      char  ch;
>      scanf ("%d",&ts);
>      for (t=0;t<ts;t++)
>      {
>          memset(num,0,sizeof(num[0]));
>          n=2;
>          scanf("%d%d",&num[0],&num[1]);
>          while(scanf("%c",&ch),ch!='\n')
>          {
>              scanf("%d",&num[n]);
>              n++;
>          }
>           if (n%2==1)
>          {
>             a=0;
>             b=0;
>             if (num[0]==0)
>             {
>                num[0]=num[1];
>                num[1]=0;
>             }
>             for (i=0;i<=n/2;i++)        a=a*10+num[i];
>             j=n/2;
>             for (i=n-1;i>j;i--)         b=b*10+num[i];
>             printf ("%d\n",a-b);
>          }
>          else
>          {
>              min=10;
>              for (i=0;i<n-1;i++)
>                    if (abs(num[i+1]-num[i])<min)
>                         min=abs(num[i+1]-num[i]);
>              flag=1000000;
>              for (i=0;i<n-1;i++)
>              {
>                  a=0;
>                  b=0;
>                  if (abs(num[i+1]-num[i])==min)
>                  {
>                       a=num[i];
>                       b=num[i+1];
>                       j=1;
>                       for (k=n-1;k>=0;k--)
>                       {
>                           if (k!=(i+1)&&(k!=i))
>                           {
>                               j++;
>                               a=a*10+num[k];
>                           }
>                           if (j==n/2) break;
>                       }
>                       j=1;
>                       for (k=0;k<n;k++)
>                       {
>                           if (k!=(i+1)&&(k!=i))
>                           {
>                               j++;
>                               b=b*10+num[k];
>                           }
>                           if (j==n/2)  break;
>                       }
>                  }
>                  if ((flag>abs(a-b))&&(abs(a-b)!=0))
>                           flag=abs(a-b);
>              }
>              printf ("%d\n",flag);
>          }
>      }
>      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