fork(3) download
  1.  
  2. /*
  3. Coder : lordzuko
  4. Time : 11:03 AM
  5. Date : 9/24/2016
  6.  
  7. */
  8.  
  9. import java.io.InputStreamReader;
  10. import java.io.IOException;
  11. import java.io.BufferedReader;
  12. import java.io.OutputStream;
  13. import java.io.PrintWriter;
  14. import java.util.HashMap;
  15. import java.util.StringTokenizer;
  16. import java.io.InputStream;
  17. import java.lang.*;
  18.  
  19.  
  20. class Main {
  21.  
  22. public static void main(String[] args) throws Exception {
  23. InputStream inputStream = System.in;
  24. OutputStream outputStream = System.out;
  25. InputReader in = new InputReader(inputStream);
  26. PrintWriter out = new PrintWriter(outputStream);
  27.  
  28. // Create an object of your solution class here
  29. BinaryPalindrome solver = new BinaryPalindrome();
  30. int n = in.nextInt();
  31. solver.solve(n, in, out);
  32. out.close();
  33. System.exit(0);
  34. }
  35. }
  36.  
  37. class BinaryPalindrome {
  38.  
  39. private int n,j;
  40. HashMap<Integer,Integer> m;
  41. public void solve(int testNumber, InputReader in, PrintWriter out) {
  42. m = new HashMap<>();
  43. j=1;
  44. for(int i=1;i<=10000000;i--){
  45. if(isPal(i)){
  46. m.put(j,i);
  47. j++;
  48. }
  49. }
  50.  
  51. while (testNumber-- >0 ){
  52. n = in.nextInt();
  53. System.out.println(m.get(n));
  54. }
  55. }
  56.  
  57.  
  58. public static boolean isPal(int orig)
  59. {
  60. int copy = orig;
  61. int reversed = 0;
  62.  
  63. while(copy!=0)
  64. {
  65. reversed <<= 1;
  66. reversed |= (copy & 1);
  67. copy >>>= 1;
  68. }
  69. return (reversed == orig);
  70. }
  71. }
  72.  
  73.  
  74. class InputReader {
  75. private BufferedReader reader;
  76. private StringTokenizer tokenizer;
  77.  
  78. public InputReader(InputStream stream) {
  79. reader = new BufferedReader(new InputStreamReader(stream));
  80. tokenizer = null;
  81. }
  82.  
  83. public String next() {
  84. while (tokenizer == null || !tokenizer.hasMoreTokens()) {
  85. try {
  86. tokenizer = new StringTokenizer(reader.readLine());
  87. } catch (IOException e) {
  88. throw new RuntimeException(e);
  89. }
  90. }
  91. return tokenizer.nextToken();
  92. }
  93.  
  94. public int nextInt() {
  95. return Integer.parseInt(next());
  96. }
  97.  
  98. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
3
2 
3 
5
compilation info
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python2.7/py_compile.py", line 117, in compile
    raise py_exc
py_compile.PyCompileError:   File "prog.py", line 2
    /*
    ^
SyntaxError: invalid syntax

stdout
Standard output is empty