import java.util.*; public class Main { public static void main(String [] args) { Scanner sc=new Scanner(System.in); while(sc.hasNext()) { //输入 String str1=sc.next(); String str2=sc.next(); //截取 String num1=str1.substring(2,str1.length()); String num2=str2.substring(1,str2.length()); //用valueOf()方法转换 System.out.print(Integer.valueOf(num1,16)+Integer.valueOf(num2,8)); } } }
利用Integer.valueOf()方法可以把其他进制转成10进制
import java.util.*; public class Main { public static void main(String [] args) { Scanner sc=new Scanner(System.in); while(sc.hasNext()) { String str1=sc.next(); String str2=sc.next(); String num1=str1.substring(2,str1.length()); String num2=str2.substring(1,str2.length()); int a=Integer.valueOf(num1,16); int b=Integer.valueOf(num2,8); System.out.println(a+b); } } }
h,shi=map(str,input("").split(' ')) total=int(h,16)+int(shi,8) print(total)
a, b = input().split() a = int(a, 16) #a必须以字符串的方式出现 b = int(b, 8) print(a + b)
nums = input().split() num1 = int(nums[0], 16) num2 = int(nums[1], 8) print(num1+num2)
class F(): def base(self,a): try: # 按照空格进行切开成列表(字符串切开是列表) a1,a2 = a.split(' ') # 进制转换 print(int(a1, 16) + int(a2, 8)) pass except Exception as e: print(e) finally: pass if __name__ == '__main__': b = input() F().base(b)