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

高手看看我这个程序错在哪里呀?测试数据和一些BT数据都通过了,就是不能AC

Posted by yeknight at 2007-04-12 22:23:10 on Problem 1001
#include <stdio.h>
#include <stdlib.h>
#include<ctype.h>
#include<math.h>
#include<string.h>

void compute(char *result,long m);
void print(char *result,int x,int n,int y);

int main(int argc, char *argv[])
{
    float m;
    int n,x,i,k;
    char mm[7],result[125];
    while(scanf("%s%d",mm,&n)!=EOF)
    {
                                   if(n==0)
                                   {
                                           printf("%d\n",1);
                                           continue;
                                   }
                                   
      m=(float)atof(mm);
      if(m==0)
      {
              printf("%d\n",0);
              continue;
      }
      k=(int)m;
      for(i=0;i<125;i++)
       result[i]='0';
      result[124]='1';
      x=0;
     for(i=5;i>=0;i--)
     {
                     if(mm[i]=='.')
                     {
                      x=5-i;
                      break;
                     }
     }
     if(m==k)
      x=0;
      m=m*pow(10,x);
      for(i=0;i<n;i++)
       compute(result,(long)m);
       print(result,x,n,k); 
    }
       
  

  return 0;
}

void compute(char *result,long m)
{
     int n,y,i;
     n=0;
     for(i=124;i>=0;i--)
     {
             y=(result[i]-'0')*m+n;
             n=y/10;
             result[i]=y%10+'0';
     }
}

void print(char *result,int x,int n,int y)
{
     
     int i,j,k=124;
     for(i=124;i>=124-x*n+1;i--)
     {
                        if(result[i]!='0')
                        {
                         k=i;
                         break;
                        }
     }
     if(y)
     {
     for(i=0;i<=k;i++)
     {
       if(result[i]!='0')
       {
         for(j=i;j<=k;j++)
         {
          printf("%c",result[j]);
          if((j==125-x*n-1)&&(x!=0))
           printf(".");
          }
          printf("\n");
          break;
       }
     }
     }
     else
     {
                          printf(".");
                          for(i=125-n*x;i<=k;i++)
                           printf("%c",result[i]);
                          printf("\n");
     }
}
          
                                       

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