Guest User

Untitled

a guest
May 26th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3. import java.math.*;
  4. import static java.lang.Math.*;
  5.  
  6. public class Main{
  7. public static void main(String[] args) throws IOException{
  8. in = new StreamTokenizer(new BufferedReader(new FileReader (new File("input.txt"))));
  9. inBuf = new BufferedReader (new FileReader (new File ("input.txt")));
  10. out = new PrintWriter(new File ("output.txt"));
  11.  
  12. int n=Integer.valueOf (nextSBuf());
  13. String num=nextSBuf();
  14. int k=Integer.valueOf (nextSBuf());
  15.  
  16. int mid=toTenth(n, num);
  17.  
  18. out.println (toKth(mid, k));
  19.  
  20. out.close();
  21. }
  22.  
  23. public static String toKth(int tenth, int to){
  24. String result="";
  25. for (;;){
  26. result=convertToChar (tenth%to, to)+result;
  27. tenth/=to;
  28. if (tenth==0) break;
  29. }
  30. return result;
  31. }
  32.  
  33. public static char convertToChar(int num, int t){
  34. String hlp="0123456789";
  35. for (char i='A'; i<='Z'; i++) hlp+=i;
  36. return hlp.charAt(num);
  37. }
  38.  
  39. public static int toTenth(int sys, String number){
  40. int res=0, power=number.length()-1;
  41.  
  42. for (int i=0; i<number.length(); i++, power--){
  43. res=res+convertToNumber(number.charAt(i))*(int)(pow (sys, power));
  44. }
  45.  
  46. return res;
  47. }
  48.  
  49. public static int convertToNumber(char c){
  50. String hlp="0123456789";
  51. for (char i='A'; i<='Z'; i++) hlp+=i;
  52. for (int i=0; i<hlp.length(); i++)
  53. if (hlp.charAt(i)==c) return i;
  54.  
  55. //never
  56. return 0;
  57. }
  58.  
  59. static StreamTokenizer in; static PrintWriter out; static BufferedReader inBuf;
  60. public static String nextSBuf() throws IOException{
  61. return inBuf.readLine();
  62. }
  63. public static long nextL() throws IOException{
  64. in.nextToken(); return (long)in.nval;
  65. }
  66. public static double nextD() throws IOException{
  67. in.nextToken(); return in.nval;
  68. }
  69. public static String nextS() throws IOException{
  70. in.nextToken(); return in.sval;
  71. }
  72. public static int nextI() throws IOException{
  73. in.nextToken(); return (int)in.nval;
  74. }
Add Comment
Please, Sign In to add comment