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. cout<<tempo<<endl;
  34. if( tempo < 10 ){
  35.  
  36. cout<<"-1"<<"\n";
  37. }
  38. else{
  39.  
  40. int found=0;
  41. for( i=0; i<strlen(num); i++){
  42.  
  43. //copy with or without leading zeroes
  44. char cpy[100];int counter=0;
  45. for( j=0; j<strlen(num); j++){
  46.  
  47. if(j==i) continue;
  48. else{
  49.  
  50. cpy[counter]=num[j];
  51. counter++;
  52. }
  53. }
  54. cpy[counter]='\0';
  55. //cout<<strlen(cpy)<<endl;
  56. //obtain number without the leading zeroes
  57. char clean[100]; int cnter=0; int bol=1;
  58. for( j=0; j<strlen(cpy); j++){
  59.  
  60. if( cpy[j]!='0' ) bol=0;
  61.  
  62. if( bol==1 ) continue;
  63.  
  64. clean[cnter]=cpy[j];
  65. cnter++;
  66. }
  67. clean[cnter]='\0';
  68. //cout<<strlen(clean)<<endl<<endl;
  69. int temp;
  70. sscanf(clean,"%d",&temp);
  71.  
  72. if( temp % 6 ==0 ){
  73.  
  74. found=1;
  75. if(temp > ans){
  76.  
  77. strcpy(correct,cpy);
  78. ans=max(ans,temp);
  79. }
  80. }
  81. }
  82.  
  83. if( found==1 ){
  84.  
  85. printf("%s\n",correct);
  86. }
  87. else{
  88.  
  89. cout<<"-1"<<"\n";
  90. }
  91. }
  92. }
  93. }
Success #stdin #stdout 0s 15232KB
stdin
1
1612345673456789
stdout
2065636501
-1