fork download
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. long long int high =0;
  6.  
  7. bool ok(long long int temp)
  8. {
  9. if(temp%3==0 && temp%2==0)
  10. return true;
  11. else
  12. return false;
  13. }
  14.  
  15. long long int check(string s, int j, int n)
  16. {
  17. long long int num=0;
  18. for(int i=0; i<n; i++)
  19. {
  20.  
  21. if(i==j)
  22. continue;
  23. else
  24. num = (10*num) + (s[i]-48);
  25.  
  26. }
  27.  
  28. if(ok(num) && num>high)
  29. {
  30. high = num;
  31. return high;
  32. }
  33. else
  34. return -1;
  35. }
  36.  
  37. int nod(int temp)
  38. {
  39. int x=0;
  40. while(temp!=0)
  41. {
  42. x++;
  43. temp = temp/10;
  44. }
  45. return x;
  46. }
  47.  
  48. int main(void)
  49. {
  50. ios::sync_with_stdio(false); cin.tie(0);
  51. int t; cin>>t;
  52. while(t--)
  53. {
  54. high =0;
  55. string s;
  56. cin>>s;
  57. long long int input=0;
  58. for(int i=0; i<s.length(); i++)
  59. {
  60. input = 10*input + (s[i]-48);
  61. }
  62. cout<<"input value: "<<input<<endl;
  63.  
  64. int sl = s.length();
  65.  
  66. long long int output=-1;
  67. for(int i=0; i<s.length(); i++)
  68. {
  69. long long int temp;
  70. temp = check(s, i, sl);
  71.  
  72. if(temp!=-1)
  73. output = temp;
  74. }
  75.  
  76. if((nod(output)!=(nod(input)-1)) && output!=-1)
  77. {
  78. for(int i=0; i<((nod(input)-1)-nod(output)); i++)
  79. cout<<"0";
  80. cout<<output<<endl;
  81. }
  82. else
  83. cout<<output<<endl;
  84.  
  85.  
  86. }
  87. return 0;
  88. }
  89.  
Success #stdin #stdout 0s 16056KB
stdin
2
123
19631233333333333333
stdout
input value: 123
12
input value: 1184489259623781717
-1