Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
这个递归太烦了,调了半天,贴代码#include <iostream> #include <math.h> using namespace std; int count[10]; int temp[10]; int c=1; void add(int v,int t) { while(v!=0) { int x=v%10; count[x]+=t; v/=10; } } void search(int v) { if(c>=10) count[0]-=c; int x=v/10; int y=v%10; for(int i=0;i<=y;i++) count[i]+=c; add(x,(y+1)*c); if(x!=0) { for(int i=0;i<=9;i++) count[i]+=x*c; c*=10; search(x-1); } } int main() { while(true) { int a,b; cin>>a>>b; if(a==0&&b==0) break; if(a>b) { int tt=a; a=b; b=tt; } search(a-1); memcpy(temp,count,10*sizeof(int)); memset(count,0,10*sizeof(int)); c=1; search(b); for(int i=0;i<9;i++) cout<<count[i]-temp[i]<<" "; cout<<count[9]-temp[9]<<endl; memset(count,0,10*sizeof(int)); c=1; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator