fork(2) download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main () {
  6. int input[10000],output[10000],cases,iL,oL;
  7. long double mul,rem;
  8. string tmp;
  9. cin >> cases;
  10. for(int i=0;i<cases;i++) {
  11. cin >> tmp;
  12. iL = 0; oL = 0;
  13. if(tmp.length()%2==1) {
  14. input[0] = tmp[0]-48;
  15. iL++;
  16. for(int j=1;j<tmp.length();iL++,j++) {
  17. input[iL] = tmp[j]-48;
  18. input[iL] = input[iL]*10 + (tmp[j+1]-48);
  19. j++;
  20. }
  21. }
  22. else {
  23. for(int j=0;j<tmp.length();iL++,j++) {
  24. input[iL] = tmp[j]-48;
  25. input[iL] = input[iL]*10 + (tmp[j+1]-48);
  26. j++;
  27. }
  28. }
  29. //for(int j=0;j<iL;j++) cout << input[j] << " "; //check input
  30. mul = 0; rem = 0;
  31. for(int j=0;j<iL;j++) {
  32. rem = rem*100 + input[j];
  33. for(int k=9;k>=0;k--) {
  34. if((mul*10+k)*k <= rem) {
  35. rem = rem - (mul*10+k)*k;
  36. //cout << "debug : " << mul*10+k << " " << rem << " ";
  37. mul = mul*10+k*2;
  38. //cout << mul << endl;
  39. output[oL] = k;
  40. oL++;
  41. break;
  42. }
  43. }
  44. }
  45. for(int j=0;j<oL;j++) cout << output[j]; //check output
  46. cout << endl;
  47. }
  48. }
Success #stdin #stdout 0s 2896KB
stdin
Standard input is empty
stdout
Standard output is empty