Google China New Grad Test 2014 Round A Problem A

Problem A. Read Phone Number

Problem

Do 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 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.

Input

The 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.

Output

For 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.

Limits

1 ≤ T ≤ 100.

Small dataset

1 ≤ length of N ≤ 10.

Large dataset

1 ≤ length of N ≤ 100.

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

解题方法:这是一道水题,二十分钟内搞定。从前向后遍历计数就可以了。

static String[] desc = new String[] { "", "", "double", "triple",
        "quadruple", "quintuple", "sextuple", "septuple", "octuple",
        "nonuple", "decuple" };
static String[] number = new String[] { "zero", "one", "two", "three",
        "four", "five", "six", "seven", "eight", "nine" };  

static void read(String s) {
    char pre = 0;
    int count = 0;
    for (int i = 0; i <= s.length(); i++) {
        char c = i == s.length() ? 0 : s.charAt(i);
        if (c != pre) {
            if (pre != 0) {
                if (count > 10) {
                    for (int j = 0; j < count; j++) {
                        System.out.print(" " + number[pre - '0']);
                    }
                } else {
                    String des = desc[count];
                    System.out.print((des.length() == 0 ? "" : " ")
                            + desc[count] + " " + number[pre - '0']);
                }
            }
            count = 1;
        } else {
            count++;
        }
        pre = c;
    }
}  

void run() {
    int tests = sc.nextInt();
    for (int test = 1; test <= tests; test++) {
        String num = sc.next();
        String format = sc.next();  

        System.out.print(String.format("Case #%d:", test));
        String[] form = format.split("-");
        int start = 0;
        for (String s : form) {
            int len = new Integer(s);
            read(num.substring(start, start + len));
            start += len;
        }
        System.out.println();  

    }
}  
时间: 2024-12-23 03:33:50

Google China New Grad Test 2014 Round A Problem A的相关文章

Google China New Grad Test 2014 Round A Problem C

Problem C. Sorting Problem Alex and Bob are brothers and they both enjoy reading very much. They have widely different tastes on books so they keep their own books separately. However, their father thinks it is good to promote exchanges if they can p

Google China New Grad Test 2014 Round A Problem B

Problem B. Rational Number Tree Problem Consider an infinite complete binary tree where the root node is 1/1 and left and right childs of node p/q are p/(p+q) and (p+q)/q, respectively. This tree looks like: 1/1 ______|______ | | 1/2 2/1 ___|___ ___|

Google 终于在 I/O 2014 大会上发布了自家车载系统 Android Auto

摘要: 上周,Google 终于在 I/O 2014 大会上发布了自家车载系统 Android Auto,自此通过屏幕投射进驻车厢的除了苹果 CarPlay 与微软的 Windows in the car,再添一员. 汽车品牌,成了这几家科技公司争 上周,Google 终于在 I/O 2014 大会上发布了自家车载系统 Android Auto,自此通过屏幕投射进驻车厢的除了苹果 CarPlay 与微软的 Windows in the car,再添一员.汽车品牌,成了这几家科技公司争夺的重要资源

Code Jam 2010 Round 1A Problem C

Problem C. Number Game Problem Arya and Bran are playing a game. Initially, two positive integers A and B are written on a blackboard. The players take turns, starting with Arya. On his or her turn, a player can replace A with A - kB for any positive

Code Jam 2010 Round 1B Problem A

Problem B. Picking Up Chicks Problem A flock of chickens are running east along a straight, narrow road. Each one is running with its own constant speed. Whenever a chick catches up to the one in front of it, it has to slow down and follow at the spe

Code Jam 2010 Round 1A Problem B

Problem B. Make it Smooth Problem You have a one-dimensional array of N pixels. Each pixel has a value, represented by a number between 0 and 255, inclusive. The distance between two pixels is the absolute difference of their numbers. You can perform

Code Jam 2010 Round 1A Problem A

Problem A. Rotate Problem In the exciting game of Join-K, red and blue pieces are dropped into an N-by-N table. The table stands up vertically so that pieces drop down to the bottom-most empty slots in their column. For example, consider the followin

google 有望回归中国

Google可能会在未来三至六个月内重启中国市场战略,以百度为首的中文搜索已经大幅吞噬Google退出空余的市场份额,而g.cn.谷歌音乐等一系列本地化措施都将面临被边缘化的危险.这对Google这样一家商业公司并不是一个好消息,所有人都知道中国将会是全球较大的互联网市场,而被视作互联网代表之一的Google却游离在这一市场之外,尽管Google已经很小心避免退出对已有业务的影响,但这种影响随着时间刻度的拉长正在变得越来越明显. 2009年1月Google首席法律顾问大卫·多姆德(David D

Google靠什么来说服用户使用Google+?

在硬核用户眼中,同为实名社交网络的Google+比Facebook优秀多了:更时尚的设计,以圈子为核心的范围可控的内容分享机制,以及那些亮眼的附加功能:Photos漂亮的高分辨率大图.优秀的图片编辑.好用的自动备份.充满灵性的自动特效和Stories:对了,还有能够轻易驾驭文字.图片以及多人视频的IM hangouts. 但与此同时,就连最忠实的用户也得承认:Google+就是Google迟来多年的Facebook竞品.除了圈子等一些亮点功能外,它本质上并无创新:笨重的实名社交,仅此而已.那么,