Read Phone Number

2014-11-24 09:09:54 · 作者: · 浏览: 0
这是Google of Greater China Test for New Grads of 2014 Round A 第一题,题目: Read Phone Number
Sample
Input
3
15012233444 3-4-4
15012233444 3-3-5
12223 2-3
Output
Case #1: one five zero one double two three three triple four
Case #2: one five zero one double two double three triple four
Case #3: one two double two three
题目非常简单,先按照format将字符串切分,例如3-4-4,将15012233444切分成3个字符串150,1223,3444,然后对每一个字符串,从前往后扫描一遍,记录连续相同字符的个数,然后按照题目给定的规则读,最后将各部分拼接在一起就OK了。
package rounda;  
  
import java.util.Scanner;  
  
public class Problem1 {  
       
    public void output(int caseNo,  String res){  
        System.out.println("Case #"+caseNo+": "+res);  
           
    }  
    public String solve(String number,String formator){  
        String[] form = formator.split("-");  
        int beginIndex=0;  
        String res = "";  
        for(int i=0;i
0){ String number = scanner.next(); String formator = scanner.next(); String result = p.solve(number,formator); p.output(T-count, result); } } }