fork download
  1. #include<iostream>
  2. #include<math.h>
  3. #include<string>
  4. using namespace std;
  5. int max( string parameter)
  6. {
  7. string a,b,s1,s2;a=parameter;
  8. long long int n1,n2,x=49,y,c,count=0,r=0,ans;char g;
  9. c=a.length();if(c>1)
  10. {
  11. for(int i=0;i<a.length();i++)
  12. {if(a[i]=='0')
  13. r++;
  14. }if (r>0)
  15. {b=a;
  16. n1=a.find_first_of("0");
  17. n2=a.find_last_of("0");
  18. b=b.erase(n1,n2-n1+1);}
  19. else b=a;
  20. for(int i=0;i<b.length();i++)
  21. {
  22. if(int(b[i])>x)
  23. x=int(b[i]);
  24. }
  25. g=char(x);
  26. for(int i=0;i<b.length();i++)
  27. {
  28. if(b[i]==g)
  29. count++;
  30. }
  31. string s[count]; long long int index[count],count1=-1;
  32. for(int i=0;i<b.length();i++)
  33. {
  34. if(b[i]==g)
  35. {count1++;
  36. int p;
  37. if(r>0)
  38. {
  39. if(i>n1-1)
  40. {
  41. p=i+n2-n1+1;}
  42. else p=i;
  43. }
  44. else p=i;
  45. index[count1]=p;
  46. }
  47. }
  48. for(int i=0;i<count;i++)
  49. {
  50. b=a;
  51. s1=b.erase(0,index[i]);
  52. b=a;
  53. s2=b.erase(index[i],c-index[i]);
  54. s[i]=s1+s2;
  55. }
  56. for(int i =0;i<count;i++)
  57. {
  58. index[i]=0;
  59. s1=s[i];
  60. for(int j=0;j<c;j++)
  61. { long int rub,dub;double bur;
  62. dub=10;
  63. bur=pow(10,c-j-2);
  64. rub=bur*dub;
  65. index[i]=index[i]+(( int(s1[j])-48)*rub);
  66. }
  67. }
  68. ans=index[0];
  69. for(int i =1;i<count;i++)
  70. {if(index[i]>ans)
  71. ans=index[i];
  72. }
  73. return ans;
  74. }
  75. else
  76. {
  77. char al;
  78. al=a[0];
  79. return int(al)-48;
  80. }
  81. }
  82. int main()
  83. {
  84. int t;
  85. cin>>t;
  86. while(t>0)
  87. {
  88. string s;
  89. cin>>s;
  90. int t1,t2,t3,r1=0;
  91. t3=s.find_first_not_of("0");s.erase(0,t3);
  92. for(int i=0;i<s.length();i++)
  93. {if(s[i]=='0')
  94. r1++;
  95. }if (r1>0)
  96. {
  97. t1=s.find_first_of("0");
  98. t2=s.find_last_of("0");
  99. }if(t1==1&&t2==s.length()-1)
  100. {
  101. string sx,sy,sz;
  102. sy=s;
  103. sy.erase(t2,1);
  104. sz=s.erase(1,1);
  105. sx=s.erase(1,t2-1);
  106. sz.erase(0,1);
  107. sz=sz+sx;int t4;
  108. t4=sz.find_first_not_of("0");sz.erase(0,t4);
  109. if(max(sz)>=max(sy))
  110. cout<<max(sz)<<endl;
  111. else
  112. cout<<max(sy)<<endl;
  113. }
  114. else
  115. cout<<max(s)<<endl;
  116. t--;
  117. }
  118. return 0;
  119. }
Success #stdin #stdout 0s 3484KB
stdin
5
1252997
60152960
72713774
24272814
62739669
stdout
9971252
9660152
7772713
8142272
9673966