题解 | #进制转换#
进制转换
http://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main{
public static void main(String[] args) throws Exception{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String str = null;
while((str=bf.readLine())!=null){
//int n=Integer.parseInt(str);
char s[]=str.toCharArray();
int sum=0;
int num;
int jinzhi[]={1,16,16*16,16*16*16,16*16*16*16,16*16*16*16*16,16*16*16*16*16*16};
int j=0;
for(int i=s.length-1;i>=2;i--){
if(s[i]-'0'>=17&&s[i]-'0'<=22){
num=s[i]-'0'-7;
sum=num*jinzhi[j]+sum;
j++;
}
if(s[i]-'0'>=0&&s[i]-'0'<=9){
num=s[i]-'0';
sum=num*jinzhi[j]+sum;
j++;
}
//sum=sum+s[i]*jinzhi[2];
}
System.out.println(sum);
//System.out.println(n);
//System.out.println(str);
//System.out.println(n);
}
}
}