fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. { int t;
  8. cin>>t;
  9. for(int ti=0;ti<t;ti++)
  10. { string s;
  11. cin>>s;
  12. bool require=false;
  13. bool equal=true;
  14. for(int i=0;i<s.length()/2;i++)
  15. { if(s[i]!=s[s.length()-i-1])equal=false;
  16. if(s[i]>=s[s.length()-i-1])s[s.length()-i-1]=s[i];
  17. else
  18. { bool possible=false;
  19. for(int j=i+1;j<=(s.length()-1)/2;j++)
  20. { if(s.length()%2==1 && j==s.length()/2 && s[j]<'9'){require=true;}
  21. if(s[j]>s[s.length()-j-1] || s[j]<'9'){possible=true;break;}
  22. }
  23. if(possible)
  24. { s[s.length()-i-1]=s[i];
  25. continue;
  26. }
  27. else
  28. { s[i]++;
  29. s[s.length()-i-1]=s[i];
  30. for(int j=i+1;j<s.length()-i-1;j++){s[j]='0';}
  31. break;
  32. }
  33. }
  34. }
  35. if(require)s[s.length()/2]++;
  36. bool inc=true;
  37. if(equal)
  38. { if(s.length()%2==1 && s[s.length()/2]<'9')
  39. { inc=false;
  40. s[s.length()/2]++;
  41. }
  42. else
  43. { for(int i=(s.length()-2)/2;i>=0;i--)
  44. { if(s[i]<'9')
  45. { inc=false;
  46. s[i]++;
  47. s[s.length()-i-1]=s[i];
  48. for(int j=i+1;j<s.length()-i-1;j++){s[j]='0';}
  49. break;
  50. }
  51. }
  52. }
  53. if(inc)
  54. { int a=s.length();
  55. s="1";
  56. for(int i=1;i<a;i++)
  57. { s=s+'0';
  58. }
  59. s=s+'1';
  60. }
  61. }
  62. cout<<s<<endl;
  63. }
  64. }
Runtime error #stdin #stdout 0s 3432KB
stdin
1
9
stdout
Standard output is empty