zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    企业面试题库1
    就业模拟试题_Net
    就业模拟试题_Java
    oracle创建用户
    Activity基础类
    Activity容器控件
    面试题_Java
    Activity功能控件
    获取工作流活动的返回值
    企业面试题库_数据库部分
  • 原文地址:https://www.cnblogs.com/ke-T3022/p/8443897.html
Copyright © 2011-2022 走看看