博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Google China New Grad Test 2014 Round A Problem A
阅读量:5913 次
发布时间:2019-06-19

本文共 3478 字,大约阅读时间需要 11 分钟。

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 315012233444 3-4-415012233444 3-3-512223 2-3Output Case #1: one five zero one double two three three triple fourCase #2: one five zero one double two double three triple fourCase #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();      }  }

转载地址:http://gsqpx.baihongyu.com/

你可能感兴趣的文章
我的友情链接
查看>>
PowerShell Switch判断语句示例
查看>>
《Spring实战》第四版读书笔记 第一章 Spring之旅
查看>>
那些年,一起学的Java 3-3
查看>>
那些年,一起学的Java 2-4
查看>>
Java中的多态和C#中的多态的区别
查看>>
UIView之【UIViewContentMode】
查看>>
yum 及手动编译rpm包
查看>>
使用Maven运行 MyBatis Generator
查看>>
7-设计模式-代理模式
查看>>
RedHat已更改其开源许可规则
查看>>
Android零基础入门第29节:善用TableLayout表格布局,事半功倍
查看>>
element-ui 的 table后端排序
查看>>
redis集群搭建
查看>>
linux重定向
查看>>
红包生成的模拟器2018今日头条秋招
查看>>
管道符和作业控制,shell变量和环境变量配置文件
查看>>
DirectX3D设备丢失(lost device)的处理(一)
查看>>
来自田野的回音——《背过身去的大娘娘》的读后感范文2600字
查看>>
LNMP架构 (Ⅱ)——nginx相关配置、nginx代理
查看>>