Advertisement
erfanul007

LOJ 1396

Dec 16th, 2019
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef unsigned long long int ull;
  5. typedef long long int ll;
  6. typedef vector<int> vi;
  7. typedef vector<ll> vll;
  8. typedef vector<vi> vvi;
  9. typedef pair<int,int > pii;
  10. typedef vector< pii > vpii;
  11. typedef set<int> sti;
  12.  
  13. #define sc scanf
  14. #define pf printf
  15. #define sci(n) scanf("%d",&n)
  16. #define scii(n,m) scanf("%d %d",&n,&m)
  17. #define scl(n) scanf("%lld",&n)
  18. #define scd(n) scanf("%lf",&n)
  19. #define scs(s) scanf("%s",s)
  20. #define pfi(n) printf("%d",n)
  21. #define pfl(n) printf("%lld",n)
  22. #define pff(n) cout<<n
  23. #define line printf("\n")
  24. #define spc printf(" ")
  25. #define clr(a,x) memset(a,x,sizeof(a))
  26. #define loop(i,x,y) for(int i=int(x); i<=int(y); i++)
  27. #define rloop(i,y,x) for(int i=int(y); i>=int(x); i--)
  28. #define cspf(i) printf("Case %d: ", i)
  29. #define vout(v) for(int w=0;w<v.size();w++){if(w) cout<<' '; cout<<v[w];}
  30. #define pb push_back
  31. #define mp make_pair
  32. #define ff first
  33. #define ss second
  34. #define all(v) v.begin(),v.end()
  35. #define rall(v) v.rbegin(),v.rend()
  36. #define read() freopen("input.txt", "r", stdin)
  37. #define write() freopen("output.txt", "w", stdout)
  38. #define fastIO() ios_base::sync_with_stdio(false); cin.tie(NULL);
  39. /// Constants
  40. #define eps 1e-9
  41. #define PI acos(-1.0) // 3.1415926535897932
  42. #define MAX 1e9
  43. #define MOD 1000007
  44.  
  45. ll GCD(ll a, ll b) { return b == 0 ? a : GCD(b , a % b); }
  46. ll LCM(ll a, ll b) { return a * (b/GCD(a, b)); }
  47.  
  48. char s[1000005];
  49.  
  50. int main()
  51. {
  52. int t;
  53. sci(t);
  54. loop(ca,1,t){
  55. scanf("%s",s);
  56. cspf(ca);
  57. bool f=false;
  58. int a,b;
  59. int ln=strlen(s);
  60. int k=(ln-1)/2;
  61. if(ln%2) a=k-1;
  62. else a=k;
  63. b=k+1;
  64. for(int i=a,j=b;i>=0;i--,j++){
  65. if(s[i]<s[j]) break;
  66. else if(s[i]>s[j]){
  67. f=true;
  68. break;
  69. }
  70. }
  71. if(f){
  72. for(int i=0,j=ln-1;i<j;i++,j--) s[j]=s[i];
  73. printf("%s\n", s);
  74. }
  75. else{
  76. f=false;
  77. int x=0;
  78. for(int i=k;i>=0;i--){
  79. if(s[i]=='9') continue;
  80. s[i]=s[i]+1;
  81. x=i;
  82. f=true;
  83. break;
  84. }
  85. if(f){
  86. for(int i=x+1;i<=k;i++) s[i]='0';
  87. for(int i=0,j=ln-1;i<j;i++,j--) s[j]=s[i];
  88. printf("%s\n", s);
  89. }
  90. else{
  91. pf("1");
  92. for(int i=1;i<ln;i++) pf("0");
  93. pf("1\n");
  94. }
  95.  
  96. }
  97. }
  98. return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement