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

真是悲剧。。。和AC程序拍了好久 就是一样的。。可是不能过 唉!

Posted by v11 at 2011-03-03 12:01:09 on Problem 2282
#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
using namespace std;
int ans[10],ten[10];
int digNum[12][3];
char s[100];
void numTostring(int n){
	int i,j;
	char str[100];
	for(i=0;n;i++,n/=10) str[i]=n%10+'0';
	for(j=0;j<i;j++) s[j]=str[i-j-1];
	s[j]=0;
	//printf("wy %s\n",s);
}
void CountNum(int num,bool fuhao){
	int i,j,k,sum,sum1,len,sum2;
	numTostring(num);
	for(i=0;s[i];i++){// choose the i-th digit
		for(j=sum=sum1=sum2=0;s[j];j++){//s[]->digNum
			if(j!=i) sum=sum*10+s[j]-'0';

			if(j<i) sum1=sum1*10+s[j]-'0';
			else if(i==j&&sum1) sum1--;
			else if(j>i) sum1=sum1*10+9;

			if(j<i) sum2=sum2*10+s[j]-'0';
			else if(j>i) sum2=sum2*10+9;
		}
		digNum[i][0]=sum+1;
		if(i==0) digNum[i][1]=0;
		else digNum[i][1]=sum1+1;
		digNum[i][2]=sum2+1;
		
	}
	len=i;
	//for(i=0;s[i];i++) printf("%d ",digNum[i][0]);puts("等于");
	//for(i=0;s[i];i++) printf("%d ",digNum[i][1]);puts("大于");
	//for(i=0;s[i];i++) printf("%d ",digNum[i][2]);puts("小于");
	for(i=0;s[i];i++){
		for(j=0;j<10;j++){//dig 0->9
			if(i==0&&j==0) continue;//第一位是 0 无效
			/*if(j==0){
				if(i!=0) ans[j]+=(digNum[i][0]-ten[len-i-1]);
			}*/
			if(j+'0'==s[i]){
				ans[j]+=digNum[i][0];
				if(j==0) ans[j]-=ten[len-i-1];
			}
			else if(j+'0'<s[i]){
				ans[j]+=digNum[i][2];
				if(j==0) ans[j]-=ten[len-i-1];
			}
			else ans[j]+=digNum[i][1];
		}
	}
	//for(i=0;i<10;i++) printf("%d ",ans[i]); puts("");
	if(fuhao){
		for(i=0;i<10;i++) ans[i]=-ans[i];
	}
}
int main(){
	int i,t,a,b;
	for(ten[0]=1,i=1;i<9;i++) ten[i]=ten[i-1]*10;
	while(cin>>a>>b){
		if(a==0&&b==0) break;
		memset(ans,0,sizeof(ans));
		if(a>b) t=a,a=b,b=t;
		CountNum(a-1,1);
		CountNum(b,0);
		for(i=0;i<9;i++)
			cout<<ans[i]<<" ";
		cout<<ans[9]<<endl;
	}
}

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