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$号水箱外,其他水箱上 ...
随机推荐
- bzoj1069 SCOI2007 最大土地面积
1069: [SCOI2007]最大土地面积 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 2560 Solved: 983 Description ...
- UDP 内网穿透 心跳
参考:http://blog.csdn.net/jacman/article/details/ 1: 启动一个Server. 2: 启动两个Client. 然后从Server端的Console里边可以 ...
- java 文件读取大全
1.按字节读取文件内容2.按字符读取文件内容3.按行读取文件内容 4.随机读取文件内容 public class ReadFromFile { /** * 以字节为单位读取文件,常用 ...
- C#实现自动升级(附源码)
http://blog.csdn.net/zhuweisky/article/details/50439386 OAUS
- --Dirring love 音乐(01背包问题)
解题思路: dp[i][j] 前 i 首歌放入 j 容量中的最大热情度. 前 i 首歌 放到 j 容量中 dp[i][j]= dp[i-1][j-m[i]]+r[i] (注意:如果 j 容量 &l ...
- mysql 外键(FOREIGN KEY)
最近有开始做一个实验室管理系统,因为分了几个表进行存储·所以要维护表间的关联··研究了一下MySQL的外键. (1)只有InnoDB类型的表才可以使用外键,mysql默认是MyISAM,这种类型不支持 ...
- Dynamic Virtual Channels
refer http://blogs.msdn.com/b/rds/archive/2007/09/20/dynamic-virtual-channels.aspx An important goal ...
- Java操作Excel(读、写、搜索关键字、插入图片)
import java.io.File; import java.io.IOException; import jxl.Cell; import jxl.Sheet; import jxl.Workb ...
- .NET设计模式(2):单件模式(Singleton Pattern)(转载)
概述 Singleton模 式要求一个类有且仅有一个实例,并且提供了一个全局的访问点.这就提出了一个问题:如何绕过常规的构造器,提供一种机制来保证一个类只有一个实例?客户程 序在调用某一个类时,它是不 ...
- 使用ymPrompt弹框
使用弹框 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8&q ...