ProblemDo you know how to read the phone numbers in English? Now let me tell you. for example, In China, the phone numbers are 11 digits, like: 15012233444. someone divides the numbers into 3-4-4 format, I. e. 150 1223 3444. while someone divides the numbers into 3-3-5 format, I. e. 150 122 33444. different formats lead to different ways to read these numbers: 150 1223 3444 reads one five zero one double two three triple four. 150 122 33444 reads one five zero one double two double three triple four. here comes the problem: Given a list of phone numbers and the dividing formats, output the right ways to read these numbers. rules: Single numbers just read them separately. 2 successive numbers use double. 3 successive numbers use triple. 4 successive numbers use quadruple. 5 successive numbers use quintuple. 6 successive numbers use sextuple. 7 successive numbers use septuple. 8 successive numbers use octuple. 9 successive numbers use nonuple. 10 successive numbers use decuple. more than 10 successive numbers read them all separately. inputThe first line of the input gives the number of test cases, T. T lines | test cases follow. each line contains a phone number N and the dividing format F, one or more positive integers separated by dashes (-), without leading zeros and whose sum always equals the number of digits in the phone number. outputFor each test case, output one line containing "Case # x: y", where x is the case number (starting from 1) and y is the reading sentence in English whose words are separated by a space. limits1 ≤t ≤100. small dataset1 ≤ length of N ≤ 10. large dataset1 ≤ length of N ≤ 100. sample Input 315012233444 3-4-415012233444 3-3-512223 2-3 Output Case #1: one five zero one double two three triple fourCase #2: one five zero one double two double three triple four
import java.util.Scanner; public class A2014 { static String []numberStr = {"zero","one","two","three","four","five","six","seven","eight","nine"}; static String []successive = {"","","double","triple","quadruple","quintuple","sextuple","septuple","octuple","nonuple","decuple"}; public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); for(int i=1; i<=t; i++) { String n = in.next(); String f = in.next(); String []fArr = f.split("-"); String res = ""; for(int j=0; j<fArr.length; j++) { int fNum = Integer.parseInt(fArr[j]); String tempN = n.substring(0, fNum); n = n.substring(fNum); res += numToStr(tempN); } System.out.println("Case #" + i + ":" + res); } } static String numToStr(String n) { String res = ""; int []num = new int[n.length()]; for(int i=0; i<n.length(); i++) { num[i] = n.charAt(i) - '0'; } int count = 1; for(int i=0; i<num.length-1; i++) { if(num[i]==num[i+1]) { count++; continue; } else { switch(count) { case 1: res += " " + numberStr[num[i]]; break; case 2: res += " " + successive[2]+" " + numberStr[num[i]]; break; case 3: res += " " + successive[3]+" " + numberStr[num[i]]; break; case 4: res += " " + successive[4]+" " + numberStr[num[i]]; break; case 5: res += " " + successive[5]+" " + numberStr[num[i]]; break; case 6: res += " " + successive[6]+" " + numberStr[num[i]]; break; case 7: res += " " + successive[7]+" " + numberStr[num[i]]; break; case 8: res += " " + successive[8]+" " + numberStr[num[i]]; break; case 9: res += " " + successive[9]+" " + numberStr[num[i]]; break; case 10: res += " " + successive[10]+" " + numberStr[num[i]]; break; } count = 1; } } switch(count) { case 1: res += " " + numberStr[num[num.length-1]]; break; case 2: res += " " + successive[2]+" " + numberStr[num[num.length-1]]; break; case 3: res += " " + successive[3]+" " + numberStr[num[num.length-1]]; break; case 4: res += " " + successive[4]+" " + numberStr[num[num.length-1]]; break; case 5: res += " " + successive[5]+" " + numberStr[num[num.length-1]]; break; case 6: res += " " + successive[6]+" " + numberStr[num[num.length-1]]; break; case 7: res += " " + successive[7]+" " + numberStr[num[num.length-1]]; break; case 8: res += " " + successive[8]+" " + numberStr[num[num.length-1]]; break; case 9: res += " " + successive[9]+" " + numberStr[num[num.length-1]]; break; case 10: res += " " + successive[10]+" " + numberStr[num[num.length-1]]; break; } return res; } }