fork download
  1. import java.math.BigInteger;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5. public static void main(String args[]) {
  6. int[] input,output;
  7. input = new int[10000];
  8. output = new int[10000];
  9. int iL,oL;
  10. BigInteger mul,rem;
  11.  
  12. Scanner cin = new Scanner(System.in);
  13. int n = cin.nextInt();
  14. int cases = n;
  15. while (n > 0) {
  16. if(n == cases)
  17. ;
  18. else
  19. System.out.println("");
  20. n--;
  21. String tmp = cin.next();
  22. iL = 0; oL = 0;
  23. if(tmp.length()%2==1) {
  24. input[0] = tmp.charAt(0)-48;
  25. iL++;
  26. for(int j=1;j<tmp.length();iL++,j++) {
  27. input[iL] = tmp.charAt(j)-48;
  28. input[iL] = input[iL]*10 + (tmp.charAt(j+1)-48);
  29. j++;
  30. }
  31. }
  32. else {
  33. for(int j=0;j<tmp.length();iL++,j++) {
  34. input[iL] = tmp.charAt(j)-48;
  35. input[iL] = input[iL]*10 + (tmp.charAt(j+1)-48);
  36. j++;
  37. }
  38. }
  39. /*for(int j=0;j<iL;j++) {
  40. System.out.print(input[j]); //check input
  41. System.out.print(" ");
  42. }*/
  43. mul = BigInteger.valueOf(0); rem = BigInteger.valueOf(0);
  44. for(int j=0;j<iL;j++) {
  45. rem = rem.multiply(BigInteger.valueOf(100));
  46. rem = rem.add(BigInteger.valueOf(input[j]));
  47. for(int k=9;k>=0;k--) {
  48. BigInteger cmp = mul;
  49. cmp = cmp.multiply(BigInteger.valueOf(10));
  50. cmp = cmp.add(BigInteger.valueOf(k));
  51. cmp = cmp.multiply(BigInteger.valueOf(k));
  52. if(cmp.compareTo(rem) < 1) {
  53. rem = rem.subtract(cmp);
  54. //cout << "debug : " << mul*10+k << " " << rem << " ";
  55. mul = mul.multiply(BigInteger.valueOf(10));
  56. mul = mul.add(BigInteger.valueOf(k*2));
  57. //cout << mul << endl;
  58. output[oL] = k;
  59. oL++;
  60. break;
  61. }
  62. }
  63. }
  64. for(int j=0;j<oL;j++) System.out.print(output[j]); //check output
  65. } //one case ends here
  66. }
  67. }
Runtime error #stdin #stdout 0.1s 380608KB
stdin
Standard input is empty
stdout
Standard output is empty