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 ! Why?

Posted by keith70 at 2009-05-13 20:27:24 on Problem 1140
In Reply To:WA ! Why? Posted by:keith70 at 2009-05-13 20:27:04
> #include<stdio.h>
> #include<stdlib.h>
> #define MAX 2000
> 
> void printans(int a[],int l)
> {
>      int i,j,m;
>      if(l<=50)
>        for(i=0;i<=l;i++) printf("%d",a[i]);
>      else
>       {   m=l/50;
>           for(i=0;i<49;i++)
>             printf("%d",a[i]);
>           printf("\n");
>           for(i=1;i<m;i++)
>             { for(j=0;j<50;j++)
>                {  
>                   printf("%d",a[j+i*50]);   
>                }
>              printf("\n");
>             }
>           for(j=m*50-1;j<=l;j++)
>             printf("%d",a[j]);
>       }
> }
> 
> int main(void)
> {
>       int i,j,k,l,num=0;
>       int m,n,d=0;
>       int ans[MAX]={0},a[MAX]={0},b[MAX][2]={0};
>       while(!scanf("%d %d",&m,&n),m||n)
>         { b[num][0]=m;b[num++][1]=n;}
>       for(;d<num;d++)     
>       {   m=b[d][0];n=b[d][1];
>           j=1;
>           a[0]=m;
>           for(i=0;i<n;)
>            {
>                 ans[i]=(m*10)/n;
>                 m=(m*10)%n;
>                 a[j++]=m;
>                 if(m==0)
>                  { 
>                    printf(".");
>                    printans(ans,i);
>                    printf("\nThis expansion terminates.\n");
>                    break;
>                  }
>                 else 
>                   for(k=0;k<j-1;k++)
>                     if(m==a[k])
>                          { 
>                            printf(".");
>                            printans(ans,i);
>                            printf("\nThe last %d digits repeat forever.\n",j-k-1); 
>                            goto loop;
>                          }
>                 
>                 i++;       
>            }
>           loop:;            
>       }
>       system("pause");
>       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