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

谁能找出我的错误,我连叫10声大哥!!!!!!! 附WA的code

Posted by kikif at 2007-09-01 10:54:56 on Problem 3286
#include <iostream>
#include <fstream>
#include <stdio.h>
using namespace std;

__int64 ls,rs;

__int64 a[30]={0,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000,10000000000};


__int64 get(__int64 s){
	if(s==0)return 1;
	int p=0;
	__int64 tmp=s;
	while(tmp!=0){
		tmp=tmp/10;
		p++;
	}
	__int64 num=0;
	for(int i=1;i<p;i++){
		__int64 tmp1=s-(s/a[i])*a[i];
		if(tmp1==0)num++;
	}
	return num;
}


__int64 cal(__int64 m){
	
	int p=0;
	__int64 tmp=m;
	while(tmp!=0){
		tmp=tmp/10;
		p++;
	}
	__int64 ans=m/10; //第一位
	
	for(int i=2;i<p;i++){
		__int64 tmp1=m/a[i];
		
		if((m-tmp1*a[i])<a[i-1]){
			__int64 leftn=(tmp1-1)*a[i-1];
			__int64 rightn=m-(m/a[i-1])*a[i-1]+1;
			ans+=leftn+rightn;
		}else{
			ans+=tmp1*a[i-1];
		}

	}
	return ans+1;
}


void main(){
	while(1){
		scanf("%I64d%I64d",&ls,&rs);
		if(ls==-1)break;
		__int64 res=cal(rs)-cal(ls)+get(ls);		
		printf("%I64d\n",res);
	}
	
}

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