标签:
//Nine one two three four five six seven eight
题目1010:A + B
时间限制:1 秒内存限制:32 兆
题目描述:
读入两个小于100的正整数A和B,计算A+B.
需要注意的是:A和B的每一位数字由对应的英文单词给出.
输入:
测试输入包含若干测试用例,每个测试用例占一行,格式为"A + B =",相邻两字符串有一个空格间隔.当A和B同时为0时输入结束,相应的结果不要输出.
输出:
对每个测试用例输出1行,即A+B的值.
样例输入:
one + two =
three four + five six =
zero seven + eight nine =
zero + zero =
样例输出:
3
90
96
/**************************************************************
Problem: 1010
User: watchfree
Language: Java
Result: Accepted
Time:90 ms
Memory:15564 kb
有bug, AC了、、
****************************************************************/
import java.util.Scanner; public class Main { static String change(String str){ if(str.equals("one")) return "1"; if(str.equals("two")) return "2"; if(str.equals("three")) return "3"; if(str.equals("four")) return "4"; if(str.equals("five")) return "5"; if(str.equals("six")) return "6"; if(str.equals("seven")) return "7"; if(str.equals("eight")) return "8"; if(str.equals("nine")) return "9"; if(str.equals("zero")) return "0"; else return ""; } static int changeNum(String str){ return Integer.parseInt(str.trim()); } public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc=new Scanner(System.in); while(sc.hasNext()){ String str=sc.nextLine(); String num[]=str.split("\\+"); String num1[]=num[0].split(" "); String tmp1="",tmp2=""; String num2[]=num[1].split(" "); for(int i=0;i<num1.length;i++){ tmp1+=change(num1[i]); } for(int i=0;i<num2.length;i++){ tmp2+=change(num2[i]); } if(changeNum(tmp1)+changeNum(tmp2)==0)break; System.out.println(changeNum(tmp1)+changeNum(tmp2)); } sc.close(); } }
标签:
原文地址:http://www.cnblogs.com/watchfree/p/5324930.html