fork download
  1. #include<string>
  2. #include<iostream>
  3. #include<cstdio>
  4. using namespace std;
  5.  
  6. bool isbigger(string a,string b,int j) // returns true if auxillary number > max
  7. {
  8. int asz=j+1,bsz=b.size(),diff=bsz-asz; //asz is size of a, sim bsz
  9. if(diff>0) while(diff--) a='0'+a;//padding0
  10. else if(diff<0){
  11. diff=-diff;
  12. while(diff--) b='0'+b; //padding 0
  13. }
  14. if(a>b) return 1;
  15. else return 0;
  16. }
  17.  
  18.  
  19. main(){
  20.  
  21. string a;
  22. cin>>a;
  23. int i,j,k,chars=0;
  24. string aux="",max="0";
  25.  
  26. for(i=0;a[i]=='0';i++);
  27. for(;a[i];i++){
  28. aux="";
  29. for(j=0;a[i+j]=='0';j++);
  30. for(;a[i+j];j++){
  31. if(a[i+j]>='A' && a[i+j]<='Z'){
  32. chars++;
  33. if(chars>1) break;
  34. aux+='9';}
  35. else aux+=a[i+j];
  36. if(isbigger(aux,max,j)) max=aux;
  37. cout<<aux<<" "<<max<<endl;
  38. }
  39. chars=0;
  40. }
  41.  
  42. if(max=="") max="0";
  43. cout<<max;
  44. }//end of code
Success #stdin #stdout 0s 2992KB
stdin
A000B99
stdout
9 9
90 90
900 900
9000 9000
9 9000
99 99
999 999
9 999
99 99
999 999
9 999
99 999
999 999
9 999
99 999
999 999
9 999
99 999
9 999
999