题解:
!!!!!!
分类讨论,情况挺多
#include<iostream> #include<cstdio> #include<cstring> using namespace std; typedef long long Lint; int TT; Lint L,R; int A[100]; int B[100]; int C[100]; int main(){ scanf("%d",&TT); while(TT--){ memset(A,0,sizeof(A)); memset(B,0,sizeof(B)); memset(C,0,sizeof(C)); scanf("%lld%lld",&L,&R); Lint x; int lenA=0; x=L; while(x){ A[++lenA]=x%10; x/=10; } int lenB=0; x=R; while(x){ B[++lenB]=x%10; x/=10; } if(lenA==lenB){ for(int i=lenA;i>=1;--i){ if(A[i]==B[i]){ C[i]=A[i]; }else{ int all0=1; for(int j=1;j<=i-1;++j)if(A[j]!=0)all0=0; if(A[i]==0){ if(all0){ C[i]=0; }else{ if(B[i]>=5){ C[i]=5; }else{ C[i]=1; } } }else{ if(((A[i]<5)||((A[i]==5)&&(all0)))&&(B[i]>=5)){ C[i]=5; }else{ if(all0){ C[i]=A[i]; }else{ C[i]=A[i]+1; } } } break; } } for(int i=lenA;i>=1;--i)printf("%d",C[i]); cout<<endl; }else{ Lint x=5; while(x<L)x*=10; if(x<=R){ printf("%lld ",x); }else{ int all0=1; for(int i=1;i<lenA;++i)if(A[i]!=0)all0=0; if(all0)x=A[lenA]; else x=A[lenA]+1; while(x<L)x*=10; printf("%lld ",x); } } } return 0; }