还是A+B

xiaoxiao2021-02-28  120

还是A+B

时间限制: 1000 ms  |  内存限制: 65535 KB 难度: 1 描述 输入两个小于100的正整数A和B,输出A+B; A,B均为每位数字对应的英文字母,结果为十进制数。 输入 A,B。 输出 A+B; 样例输入 one + two = one + two zero = 样例输出 3 21

import java.util.Scanner; public class Main { public static int judge(String str) { String num[] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }; for (int i = 0; i < num.length; i++) { if (str.equals(num[i])) { return i; } } return -1; } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { int numone = 0, numtwo = 0; String string = scanner.next(); while (judge(string) != -1) { numone = numone * 10 + judge(string); string = scanner.next(); } string = scanner.next(); while (judge(string) != -1) { numtwo = numtwo * 10 + judge(string); string = scanner.next(); } System.out.println(numone + numtwo); } } }

转载请注明原文地址: https://www.6miu.com/read-64873.html

最新回复(0)