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

现在5:57PM,谁来救我?

Posted by Manio at 2006-01-22 05:57:44 on Problem 2719
/*final3*/
#include <stdio.h>
#include <math.h>
long d(long n)
{
 if(n==10)return 1;
 return d(n/10)*9+n/10;
}

/* get the last digit */
long GetLastDigit ( long x )
{
 return (long)( (x/10.0+0.0009-x/10) *10   );
}


long GetCount4(double x)
{
 double temp;
 long count4 = 0 ;
 long wei = 0,last;

 if(  ( x/10.0 - floor(x/10) ) > 0.4 ) {
	count4++;
   }

 x = floor(x/10);
 wei = 10;
 while( x >= 1 ){
   last = GetLastDigit(x);

   if( last != 0 ){
	if( last > 4){
		count4 = (last-1) * d(wei) + wei + count4;

	  }/*if inside*/
	else{
		count4 = last * d(wei) + count4;

	}
   }/*if*/
   x = floor(x/10);
   wei *=10;
 }/*while*/
 return (count4);

}/*GetCount4*/

main()
{
double myx[100000];
long i = 0;
scanf("%f",&myx[0]);

while(myx[i]!=0)
{
 i++;
 scanf("%f",&myx[i]);
}
i = 0;
while(myx[i]!=0){
 printf("%ld: %ld\n",(long)myx[i],((long)(myx[i]))-GetCount4(myx[i]) );
 i++;
}
}/*main*/

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