ACdream 1188 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
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 (字符串大模拟)的更多相关文章
- 【字符串大模拟】潜伏者—— NOIP2009原题
洛谷连接 就一道黄题没啥可以说的……就是要细心…… 学到了神奇的优化 ios::sync_with_stdio(false); cin优化,能跑的比scanf快!棒!(不过要开std) 这题真的还挺简 ...
- 2016ACM-ICPC网络赛北京赛区 1001 (trie树牌大模拟)
[题目传送门] 1383 : The Book List 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 The history of Peking University ...
- NOIP2017 时间复杂度 大模拟
再写一道大模拟题. 由于是限时写的,相当于考场代码,乱的一批. 题目链接:P3952 时间复杂度 先记几个教训: 字符串形式的数字比较大小老老实实写函数,字典序都搞错几次了 栈空的时候不但pop()会 ...
- Codeforces 730L - Expression Queries(大模拟)
Codeforces 题面传送门 & 洛谷题面传送门 大模拟(?)+阿巴细节题,模拟赛时刚了 3h 最后因为某个细节写挂 100->40/ll/ll(下次一定不能再挂分了啊 awa) 首 ...
- HDU 5920 Ugly Problem 高精度减法大模拟 ---2016CCPC长春区域现场赛
题目链接 题意:给定一个很大的数,把他们分为数个回文数的和,分的个数不超过50个,输出个数并输出每个数,special judge. 题解:现场赛的时候很快想出来了思路,把这个数从中间分为两部分,当位 ...
- AC日记——神奇的幻方 洛谷 P2615(大模拟)
题目描述 幻方是一种很神奇的N*N矩阵:它由数字1,2,3,……,N*N构成,且每行.每列及两条对角线上的数字之和都相同. 当N为奇数时,我们可以通过以下方法构建一个幻方: 首先将1写在第一行的中间. ...
- Bzoj1972: [Sdoi2010]猪国杀 题解(大模拟+耐心+细心)
猪国杀 - 可读版本 https://mubu.com/doc/2707815814591da4 题目可真长,读题都要一个小时. 这道题很多人都说不可做,耗时间,代码量大,于是,本着不做死就不会死的精 ...
- (大模拟紫题) Luogu P1953 易语言
原题链接:P1953 易语言 (我最近怎么总在做大模拟大搜索题) 分别处理两种情况. 如果只有一个1或0 直接设一个cnt为这个值,每次输入一个新名字之后把数字替换成cnt,最后cnt++即可. 注意 ...
- [CSP-S模拟测试]:引子(大模拟)
题目描述 网上冲浪时,$Slavko$被冲到了水箱里,水箱由上而下竖直平面.示意图如下: 数字$i$所在的矩形代表一个编号为$i$的水箱.1号水箱为水箱中枢,有水管连出.除了$1$号水箱外,其他水箱上 ...
随机推荐
- CentOS 6.5(6.4)安装过程图文教程
CentOS 6.4是最新的出的系统,这里分享下安装教程,有些设置大部分教程没出现过,特分享下,方便需要的朋友 1.首先,要有一张CentOS 6.4的安装介质,使用介质启动电脑出现如下界面 界面说明 ...
- 修改eclipse/MyEclipse中包的显示结构为树形
在右上边三角那里进去设置 选第一个是显示完整的包名,第二个显示的是树形结构,我们一般用第一种,如下图:
- tomcat管理页面用户角色、用户名、用户密码的配置
参考资料:http://www.365mini.com/page/tomcat-manager-user-configuration.htm 编辑tomcat/conf/tomcat-users.xm ...
- Spring MVC 读取静态资源时404错误
背景:web.xml配置时拦截策略是拦截所有请求: <servlet> <servlet-name>springmvc</servlet-name> <ser ...
- Matalab IFS分形算法
IFS 算法代码 function IFS_draw(M,p) N=; :length(p); eval(['a',num2str(k),'=reshape(M(',num2str(k),',:),2 ...
- Unity自动打包Apk
unity打包apk相对来说比较容易,相信出过的人都明白,出包过程,没有大的难度,一步一操作,一步一等待,繁琐耗时,不懂的人又代替不了.这时候需求就来了,如何简单的一键打包搞定,这个就稍微有点难度,当 ...
- Linux下SVN安装配置和使用中遇到的问题
两个命令: svn info :显示版本库信息,svn的下载url等. svn co https://xxxxx/xxx wodemulu (通过我的目录制定co的文件夹) svn st:显示 ...
- myBatis 实现用户表增操作(复杂型)
增加 @Test public void addTest(){ String resource = "mybatis-config.xml"; SqlSession sqlSess ...
- C++_Eigen函数库用法笔记——Matrix and Vector Arithmetic
Addition and subtraction Scalar multiplication and division Transposition Matrix-matrix and matrix-v ...
- @suppressWarnings解释
J2SE 提供的最后一个批注是 @SuppressWarnings.该批注的作用是给编译器一条指令,告诉它对被批注的代码元素内部的某些警告保持静默. 一点背景:J2SE 5.0 为 Java 语言增加 ...