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 purplefly at 2006-06-18 13:26:09 on Problem 2710
#include<stdio.h>
#include<math.h>
#define N 300

int DtoS(int n)
{ int i,m,b[N];
  i=0;
  while(n)
  {  b[i]=n%7;
     n=n/7;
	 i++;
  }
  
  m=0;
  
  while(i--)
  m+=b[i]*pow(10,i);

  return m;

}

int StoD(int n)
{ int i,b,c,cout=0;
  i=1;
  c=10;

  while(n/c)
  {i++;
   c*=10;
  }

  c=1;
  b=1;
  while(i--)
  { cout+=(n/b%10)*c;
    c*=7;
	b*=10;
  }
  return cout;

}

int max(int a,int b)
{ if(a>=b) return a;
  else return b;
}


int min(int a,int b)
{ if(a>=b) return b;
  else return a;
}

void main()
{ int n,d,b,e,i,a[N],num,set;
  scanf("%d",&num);
  set=1;
  while(num--)
  {
    scanf("%d%d%d%d",&n,&d,&b,&e);
   printf("Problem set %d: %d / %d, base 7 digits %d through %d: ",set,n,d,b,e);
  n%=d;
  n=DtoS(n);
  d=DtoS(d);

  i=0;
  while(i<=max(b,e))
  { a[i]=StoD(10*n)/StoD(d);
    n=StoD(10*n)%StoD(d);
	n=DtoS(n);
  i++;
  }
  
  i=min(b,e);
  
  while(i<=max(b,e))
  {printf("%d",a[i]);
   i++;
  }
  
  set++;
  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