Advertisement
Guest User

palindrom

a guest
Oct 31st, 2014
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. //start
  2.  
  3.         int n = strToInt(args[0]);
  4.  
  5.         int dis = 9;
  6.         int end = 10;
  7.         int i = 1;
  8.         for ( ; n > dis; i++) {
  9.  
  10.             n -= dis;
  11.             if (i % 2 == 0) {
  12.                 dis *= 10;
  13.                 end *= 10;
  14.             }
  15.  
  16.  
  17.         }
  18.  
  19.         int start = end/10;
  20.  
  21.         int c = 1;
  22.  
  23.         for ( ; start < end; start++) {
  24.  
  25.             if (c == n)
  26.                 break;
  27.             c++;
  28.  
  29.         }
  30.         int add;
  31.         if (i % 2 == 0) {
  32.  
  33.             add = convert(start);
  34.             start *= end;
  35.  
  36.         } else {
  37.  
  38.             add = convert(start/10);
  39.             start *= end/10;
  40.  
  41.         }
  42.  
  43.         //end
  44.  
  45.         int res = start + add;
  46.         core.out(res + " : answer");
  47.  
  48.  
  49.  
  50.  
  51.     }
  52.  
  53.     public int convert(int i) {
  54.  
  55.         int r = 0;
  56.         while (i > 0) {
  57.             r = 10 * r + i % 10;
  58.             i = i / 10;
  59.         }
  60.  
  61.         return r;
  62.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement