输入两个非负10进制整数A和B(<=230-1),输出A+B的D (1 < D <= 10)进制数。
输入格式:
输入在一行中依次给出3个整数A、B和D。
输出格式:
输出A+B的D进制数。
输入样例:123 456 8输出样例:
1103
import java.util.Scanner; /** * @author jwang1 Success Factors */ public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int a = cin.nextInt(); int b = cin.nextInt(); int d = cin.nextInt(); int c = a + b; StringBuffer sb = new StringBuffer(); while (c != 0) { int temp = c % d; c /= d; sb.append(temp); } for (int i = sb.length() - 1; i >= 0; i--) { System.out.print(sb.charAt(i)); } if(sb.length() == 0) { System.out.print(0); } System.out.println(); } }
1022. D进制的A+B (20),布布扣,bubuko.com
原文地址:http://blog.csdn.net/jason_wang1989/article/details/25612899