HDU1877 又一版 A+B

Problem Description
输入两个不超过整型定义的非负10进制整数A和B(<=231-1),输出A+B的m (1 < m <10)进制数。



 

 

Input
输入格式:测试输入包含若干测试用例。每个测试用例占一行,给出m和A,B的值。
当m为0时输入结束。
 

 

Output
输出格式:每个测试用例的输出占一行,输出A+B的m进制数。
 

 

Sample Input
8 1300 48
2 1 7 0
 

 

Sample Output
2504
1000
 
 1 import java.util.Scanner;
 2 
 3 public class HDU1877 {
 4 
 5     public static void main(String[] args) {
 6         // TODO Auto-generated method stub
 7             Scanner input = new Scanner(System.in);
 8             for(;;){
 9                 int jinzhi = input.nextInt();
10                 if(jinzhi==0){
11                     break;
12                 }else{
13                     int a = input.nextInt();
14                     int b = input.nextInt();
15                     int c = a+b;
16                     
17                     int i = 0;
18                     int k = 0;
19                     int s = 0;
20                     while(c!=0){
21                         k = c%jinzhi;
22                         s+=k*(int)Math.pow(10, i);
23                         i++;
24                         c=c/jinzhi;
25                         
26                     }
27                     System.out.println(s);
28                 }
29             }
30         
31 
32         
33 
34             
35     }
36 
37 }
View Code

 

posted on 2018-02-12 10:29  柯腾  阅读(137)  评论(0编辑  收藏  举报