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

Why WA ?????Why????Help!!!

Posted by javawin at 2011-03-30 21:03:50 on Problem 1140
谁帮我看看,,为什么就一直WA啊!!!给我的测试数据都过了的,,自己写的数据也过了!!怎么回事儿啊!!!谁能告诉我一下,,谢谢了。。zouqibo2009@163.com

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
#define MAX 1001
bool flag[MAX];
int a[MAX];
char s[10000];
void print(){
    //int t=0;
    for(int i=0;s[i]!='\0';i++){
        if(i%50==0&&(s[i+1]!='\0'))printf("\n");
        printf("%c",s[i]);
    }
    printf("\n");
}
int main(){
    int x,y;
    while(scanf("%d%d",&x,&y)){
        if(x==0&&y==0)break;
         if(x==0||x%y==0){
            printf(".0\n");
            printf("This expansion terminates.\n");
             continue;
         }
        memset(s,'\0',sizeof(s));
        memset(flag,0,sizeof(flag));
        s[0]='.';
        x%=y;
        int t=1;
        flag[x]=true;
      while(true){
          if(x%y==0){
              print();
              //printf("%s\n",s);
              printf("This expansion terminates.\n");
              break;
          }

          if(x<y){
              x*=10;
          }
          while(x<y){
              x*=10;
              s[t]='0';
              t++;
          }
           if(flag[x%y]){
               s[t]=x/y+'0';
              print();
              //printf("%s\n",s);
              printf("The last %d digits repeat forever.\n",t-a[x%y]);
              break;
          }
          //printf("****%d\n",x%y);

          s[t]=x/y+'0';
          x%=y;
          flag[x]=true;
          //printf("##%d  %c\n",x,s[t]);
          a[x]=t;
          t++;
      }
    }
}


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