fork download
  1. /*AUTHOR: kriskhundu */
  2.  
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5.  
  6. #define FOR(i,a,b) for(int i=a;i<b;i++)
  7. #define FORD(i,a,b) for(int i=a;i>=b;i--)
  8. #define REP(i,n) FOR(i,0,n)
  9. #define PB push_back
  10. #define ITER(i,a) for( typeof(a.begin()) i=a.begin();i!=a.end();i++)
  11. #define mod 1000000007
  12. #define MAXN 1000010
  13. #define MEM(a,b) memset(a,(b),sizeof(a))
  14. #define MP make_pair
  15. #define INF mod
  16.  
  17. typedef vector<int> VI;
  18. typedef long long LL;
  19. typedef list<int> LI;
  20.  
  21. int main()
  22. {
  23. int TC;
  24. scanf("%d",&TC);
  25. while(TC--){
  26.  
  27. char num[100],correct[100]; int i,j;/*iterator*/ int ans=-1;
  28. scanf("%s",num);
  29. //cout<<strlen(num)<<endl;
  30. //
  31. int tempo;
  32. sscanf(num,"%d",&tempo);
  33. if( tempo < 10 ){
  34.  
  35. cout<<"-1"<<"\n";
  36. }
  37. else{
  38.  
  39. int found=0;
  40. for( i=0; i<strlen(num); i++){
  41.  
  42. //copy with or without leading zeroes
  43. char cpy[100];int counter=0;
  44. for( j=0; j<strlen(num); j++){
  45.  
  46. if(j==i) continue;
  47. else{
  48.  
  49. cpy[counter]=num[j];
  50. counter++;
  51. }
  52. }
  53. cpy[counter]='\0';
  54. //cout<<strlen(cpy)<<endl;
  55. //obtain number without the leading zeroes
  56. char clean[100]; int cnter=0; int bol=1;
  57. for( j=0; j<strlen(cpy); j++){
  58.  
  59. if( cpy[j]!='0' ) bol=0;
  60.  
  61. if( bol==1 ) continue;
  62.  
  63. clean[cnter]=cpy[j];
  64. cnter++;
  65. }
  66. clean[cnter]='\0';
  67. //cout<<strlen(clean)<<endl<<endl;
  68. int temp;
  69. sscanf(clean,"%d",&temp);
  70.  
  71. if( temp % 6 ==0 ){
  72.  
  73. found=1;
  74. if(temp > ans){
  75.  
  76. strcpy(correct,cpy);
  77. ans=max(ans,temp);
  78. }
  79. }
  80. }
  81.  
  82. if( found==1 ){
  83.  
  84. printf("%s\n",correct);
  85. }
  86. else{
  87.  
  88. cout<<"-1"<<"\n";
  89. }
  90. }
  91. }
  92. }
Runtime error #stdin #stdout 0s 16064KB
stdin
1
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
stdout
Standard output is empty