Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- import java.math.*;
- import static java.lang.Math.*;
- public class Main{
- public static void main(String[] args) throws IOException{
- in = new StreamTokenizer(new BufferedReader(new FileReader (new File("input.txt"))));
- inBuf = new BufferedReader (new FileReader (new File ("input.txt")));
- out = new PrintWriter(new File ("output.txt"));
- int n=Integer.valueOf (nextSBuf());
- String num=nextSBuf();
- int k=Integer.valueOf (nextSBuf());
- int mid=toTenth(n, num);
- out.println (toKth(mid, k));
- out.close();
- }
- public static String toKth(int tenth, int to){
- String result="";
- for (;;){
- result=convertToChar (tenth%to, to)+result;
- tenth/=to;
- if (tenth==0) break;
- }
- return result;
- }
- public static char convertToChar(int num, int t){
- String hlp="0123456789";
- for (char i='A'; i<='Z'; i++) hlp+=i;
- return hlp.charAt(num);
- }
- public static int toTenth(int sys, String number){
- int res=0, power=number.length()-1;
- for (int i=0; i<number.length(); i++, power--){
- res=res+convertToNumber(number.charAt(i))*(int)(pow (sys, power));
- }
- return res;
- }
- public static int convertToNumber(char c){
- String hlp="0123456789";
- for (char i='A'; i<='Z'; i++) hlp+=i;
- for (int i=0; i<hlp.length(); i++)
- if (hlp.charAt(i)==c) return i;
- //never
- return 0;
- }
- static StreamTokenizer in; static PrintWriter out; static BufferedReader inBuf;
- public static String nextSBuf() throws IOException{
- return inBuf.readLine();
- }
- public static long nextL() throws IOException{
- in.nextToken(); return (long)in.nval;
- }
- public static double nextD() throws IOException{
- in.nextToken(); return in.nval;
- }
- public static String nextS() throws IOException{
- in.nextToken(); return in.sval;
- }
- public static int nextI() throws IOException{
- in.nextToken(); return (int)in.nval;
- }
Add Comment
Please, Sign In to add comment