Read Phone Number

Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu

Description

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(1 ≤ T ≤ 100).

T test cases follow. Each line contains a phone number N(1 ≤ length of N ≤ 100) 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.

Sample Input

3
15012233444 3-4-4
15012233444 3-3-5
12223 2-3

Sample 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
题意样例输入输出就能看懂,注意10个以上数字要单独输出,是个字符串大模拟。
#include <iostream>
#include <cstdio>
#include <string.h>
using namespace std;
char data[][]={"double","triple","quadruple","quintuple","sextuple",
"septuple","octuple","nonuple","decuple"};
char aa[][]={"zero","one","two","three","four","five","six","seven","eight","nine","decuple"};
int main()
{
int t,cas=;
scanf("%d",&t);
while(t--)
{
char c[],d[];
scanf("%s",c);
scanf("%s",d);
int len1=strlen(c);
int len2=strlen(d);
int a[];
for(int i=;i<len1;i++)
a[i]=c[i]-'';
int fen[],cnt=,tmp=;
printf("Case #%d:",cas++);
for(int i=;i<len2;i++)
{
if(d[i]!='-')
{
tmp=tmp*;
tmp+=d[i]-'';
}
else
{
fen[cnt++]=tmp;
tmp=;
}
}
if(tmp) fen[cnt++]=tmp;
//for(int i=0;i<cnt;i++)
//cout<<fen[i]<<endl;
int b=;
int sum=;
for(int i=;i<cnt;i++)
{
b=;
for(int j=sum;j<sum+fen[i];j++)
{
if(j+<sum+fen[i])
{
if(a[j]==a[j+])
b++;
else
{
if(b==)
{
cout<<" "<<aa[a[j]];
}
else if(b>&&b<=)
{
cout<<" "<<data[b-]<<" "<<aa[a[j]];
b=;
}
else
{
for(int k=;k<b;k++)
cout<<" "<<aa[a[j]];
b=;
}
}
}
else //最后一个字符了
{
if(b==)
{
cout<<" "<<aa[a[j]];
}
else if(b>&&b<=)
{
cout<<" "<<data[b-]<<" "<<aa[a[j]];
b=;
}
else
{
for(int k=;k<b;k++)
cout<<" "<<aa[a[j]];
b=;
}
}
}
sum+=fen[i];
}
cout<<endl;
}
return ;
}
 

ACdream 1188 Read Phone Number (字符串大模拟)的更多相关文章

  1. 【字符串大模拟】潜伏者—— NOIP2009原题

    洛谷连接 就一道黄题没啥可以说的……就是要细心…… 学到了神奇的优化 ios::sync_with_stdio(false); cin优化,能跑的比scanf快!棒!(不过要开std) 这题真的还挺简 ...

  2. 2016ACM-ICPC网络赛北京赛区 1001 (trie树牌大模拟)

    [题目传送门] 1383 : The Book List 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 The history of Peking University ...

  3. NOIP2017 时间复杂度 大模拟

    再写一道大模拟题. 由于是限时写的,相当于考场代码,乱的一批. 题目链接:P3952 时间复杂度 先记几个教训: 字符串形式的数字比较大小老老实实写函数,字典序都搞错几次了 栈空的时候不但pop()会 ...

  4. Codeforces 730L - Expression Queries(大模拟)

    Codeforces 题面传送门 & 洛谷题面传送门 大模拟(?)+阿巴细节题,模拟赛时刚了 3h 最后因为某个细节写挂 100->40/ll/ll(下次一定不能再挂分了啊 awa) 首 ...

  5. HDU 5920 Ugly Problem 高精度减法大模拟 ---2016CCPC长春区域现场赛

    题目链接 题意:给定一个很大的数,把他们分为数个回文数的和,分的个数不超过50个,输出个数并输出每个数,special judge. 题解:现场赛的时候很快想出来了思路,把这个数从中间分为两部分,当位 ...

  6. AC日记——神奇的幻方 洛谷 P2615(大模拟)

    题目描述 幻方是一种很神奇的N*N矩阵:它由数字1,2,3,……,N*N构成,且每行.每列及两条对角线上的数字之和都相同. 当N为奇数时,我们可以通过以下方法构建一个幻方: 首先将1写在第一行的中间. ...

  7. Bzoj1972: [Sdoi2010]猪国杀 题解(大模拟+耐心+细心)

    猪国杀 - 可读版本 https://mubu.com/doc/2707815814591da4 题目可真长,读题都要一个小时. 这道题很多人都说不可做,耗时间,代码量大,于是,本着不做死就不会死的精 ...

  8. (大模拟紫题) Luogu P1953 易语言

    原题链接:P1953 易语言 (我最近怎么总在做大模拟大搜索题) 分别处理两种情况. 如果只有一个1或0 直接设一个cnt为这个值,每次输入一个新名字之后把数字替换成cnt,最后cnt++即可. 注意 ...

  9. [CSP-S模拟测试]:引子(大模拟)

    题目描述 网上冲浪时,$Slavko$被冲到了水箱里,水箱由上而下竖直平面.示意图如下: 数字$i$所在的矩形代表一个编号为$i$的水箱.1号水箱为水箱中枢,有水管连出.除了$1$号水箱外,其他水箱上 ...

随机推荐

  1. [IOS SQLITE的使用方式]

    1.把数据库文件localdata.db放入工程,并建立bundle(在build phases里) 2.创建新的类,用于本地SQLite查询. LocalDB.m(.h就不说了,保证每个.m里要外部 ...

  2. groovy-真值

    Boolean expressions Groovy支持标准的条件运算符的布尔表达式: 1 def a = true 2 def b = true 3 def c = false 4 assert a ...

  3. python运行报错:urllib2.URLError: <urlopen error [Errno 10061] >

    Traceback (most recent call last): File "F:\adt-bundle-windows-x86_64-20140702\eclipse\workspac ...

  4. 文件流StreamReader和StreamWriter的使用

    using (StreamReader sr = new StreamReader(@"C:\Users\shuai\Desktop\文件流读取.txt", Encoding.De ...

  5. JavaScript input file上传前获取文件名、文件类型、文件大小等信息

    document.getElementById("productImgInput").files[0].type document.getElementById("pro ...

  6. 在CentOS 7上利用systemctl添加自定义系统服务

    每一个服务以.service结尾,一般会分为3部分:[Unit].[Service]和[Install],具体内容如下: [Unit]Description=*****After=network.ta ...

  7. WPF 窗口自定义拉伸

    .NET技术交流群 199281001 .欢迎加入. //自定义窗体拉伸 public HwndSource _HwndkaifaSource; private const int WM_SYSCOM ...

  8. Hibernate unsaved-value 属性

    Session的saveOrUpdate方法是由Hibernate来判断被操作对象究竟是一个持久化对象还是临时自由状态对象.这需要在对象映射文件的主键id中定义unsaved-value属性,如果不显 ...

  9. JQUERY 模糊选择

    JQUERY 模糊选择        [属性名称]         匹配包含给定属性的元素      [att=value]       匹配包含给定属性的元素      [att*=value]   ...

  10. 《PHP程序设计》读书笔记

    好久没有更新过我的博客了,主要前一阵子去了实习,现在实习进入尾声,终于有机会看看书了. 在前一阵子的实习中,用到最多就是PHP的CI框架和Jquery,所以现在再看一本有关PHP的书籍来深刻认识一下P ...