杭电oj(Java版)——1720 A+B Coming

来源:互联网 发布:mac怎么保存文档 编辑:程序博客网 时间:2024/05/29 07:13

A+B Coming

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 9152    Accepted Submission(s): 5979


Problem Description
Many classmates said to me that A+B is must needs.
If you can’t AC this problem, you would invite me for night meal. ^_^
 

Input
Input may contain multiple test cases. Each case contains A and B in one line.
A, B are hexadecimal number.
Input terminates by EOF.
 

Output
Output A+B in decimal number in one line.
 

Sample Input
1 9A Ba b
 

Sample Output
102121
import java.util.Scanner;public class Main{public static void main(String[] args) {Scanner scanner = new Scanner(System.in);while (scanner.hasNext()) {String str = scanner.nextLine();str = str.toLowerCase();str = str.replace(" ", "");char arr[] = str.toCharArray();int a = 0;int b = 0;switch (arr[0]) {case '0':a = 0;break;case '1':a =1;break;case '2':a = 2;break;case '3':a = 3;break;case '4':a = 4;break;case '5':a = 5;break;case '6':a = 6;break;case '7':a = 7;break;case '8':a = 8;break;case '9':a = 9;break;case 'a':a = 10;break;case 'b':a = 11;break;case 'c':a = 12;break;case 'd':a = 13;break;case 'e':a = 14;break;case 'f':a = 15;break;}switch (arr[1]) {case '0':b = 0;break;case '1':b =1;break;case '2':b = 2;break;case '3':b = 3;break;case '4':b = 4;break;case '5':b = 5;break;case '6':b = 6;break;case '7':b = 7;break;case '8':b = 8;break;case '9':b = 9;break;case 'a':b = 10;break;case 'b':b = 11;break;case 'c':b = 12;break;case 'd':b = 13;break;case 'e':b = 14;break;case 'f':b = 15;break;}System.out.println(a+b);}}}


0 0
原创粉丝点击