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

还是WA 谁能指点一下

Posted by zzningxp at 2005-09-12 18:40:02 on Problem 2611
In Reply To:为什么会WA hawk加了什么数据 还是写题风格或是编译器差别? Posted by:zzningxp at 2005-09-11 18:13:12
#include <stdio.h>
#include <string.h>

int main()
{
  char st[40];
  int i,j,k,m,r,d,ln,t,a[40]={0};
  while (scanf("%s",st) && st[0]!='.')
  {
    ln=strlen(st)-1;
    for (d=-1,i=0;i<=ln;i++)
    {
      if (st[i]=='.')
        d=i;
      if (d==-1)
        a[i]=st[i]-'0';
      else
        if (st[i]!='.')
          a[i-1]=st[i]-'0';
    }

    a[ln]=0;

    for (i=ln-1;i>=0;i--)
      if ((a[i]==2 || a[i]==6) &&
          (a[i]+3<a[i+1] || a[i]>=a[i+1]))
      {
        a[i]+=3;
        for (j=i+1;j<ln;j++)
          if (a[j]==5 || a[j]==9)
            a[j]-=3;
        for (j=i+1;j<ln;j++)
          for (k=j+1;k<ln;k++)
            if (a[j]>a[k])
            {
              t=a[j];
              a[j]=a[k];
              a[k]=t;
            }
        break;
      }
      else
      if (a[i]<a[i+1])
      {
        m=20;
        r=i;
        k=0;
        for (j=ln-1;j>i;j--)
        {
          if (a[j]>a[i])
            if (a[j]-a[i]<m)
            {
              m=a[j]-a[i];
              r=j;
            }
          if ((a[j]==5 || a[j]==9) && a[j]-3>a[i])
            if (a[j]-3-a[i]<m)
            {
              m=a[j]-3-a[i];
              r=j;
              k=1;
            }
        }
        if (k)
          a[r]-=3;

        t=a[i];
        a[i]=a[r];
        a[r]=t;

        for (j=i+1;j<ln;j++)
          if (a[j]==5 || a[j]==9)
            a[j]-=3;

        for (j=i+1;j<ln;j++)
          for (k=j+1;k<ln;k++)
            if (a[j]>a[k])
            {
              t=a[j];
              a[j]=a[k];
              a[k]=t;
            }
        break;
      }
    if (i<0)
      printf("The price cannot be raised.");
    else
      for (i=0;i<ln;i++)
      {
        if (i==d)
          printf(".");
        printf("%d",a[i]);
      }
    printf("\n");
  }
  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