一道耗时间的水题

Time Limit: 2000/1000ms (Java/Others)

Problem 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 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
解题思路:这道题的题意比较简单,处理起来比较麻烦,但掌握了这个知识点(C++的获取子串的函数substr()),就简单多了:basic_string substr( size_type index, size_type num = npos );substr()返回本字符串的一个子串,从index开始,长num个字符。如果没有指定,将是默认值 string::npos。这样,substr()函数将简单的返回从index开始的剩余的字符串。对应每个子串中某个字符出现的次数n如果为1时,则只输出该字符对应的英语单词;如果大于10,则输出n个该字符对应的英语单词;否则(n>1&&n<=10)输出n对应倍数单词和该字符对应的英语单词。
AC代码:
 #include<bits/stdc++.h>
using namespace std;
const int maxn = ;//因为字符串s2中可能会出现100个'1',所以这里取105
const string str1[]={"decuple","","double","triple","quadruple","quintuple","sextuple","septuple","octuple","nonuple"};
const string str2[]={"zero","one","two","three","four","five","six","seven","eight","nine"};
int t,n,k,x,s[maxn],e[maxn];string s1,s2,tp[maxn];//s数组记录截取字符串s1的起始位置,e数组记录截取字符的个数
int main(){
cin>>t;getchar();//吃掉回车符对字符串的影响
for(int i=;i<=t;++i){
cin>>s1>>s2;s[]=k=x=;//s[0]起始位置为0,k记录分成子串的个数
cout<<"Case #"<<i<<":";
for(unsigned int j=;j<=s2.length();++j){
if(s2[j]=='-'||s2[j]=='\0'){e[k++]=x;x=;}
else x=x*+s2[j]-'';
}
for(int j=;j<k;++j)s[j+]=s[j]+e[j];//累加起始位置
for(int j=;j<k;++j)tp[j]=s1.substr(s[j],e[j]);//获得对应子串
for(int j=;j<k;++j){n=;//n记录相同元素的个数,初始值为1
for(unsigned int h=;h<tp[j].length();++h){
if(tp[j][h]!=tp[j][h+]){
if(<n&&n<=)cout<<" "+str1[n%];//取余操作
if(n<=)cout<<" "+str2[tp[j][h]-''];
else{//n大于10,则输出n个对应的字符串
for(int m=;m<=n;++m)
cout<<" "+str2[tp[j][h]-''];
}n=;//n重置为1
}
else n++;//相同个数加1
}
}
cout<<endl;
}
return ;
}

ACM_一道耗时间的水题的更多相关文章

  1. 关于一道你们眼中的水题 Windy数 的乱写(数位dp)

    啊一道水题有什么好说的 上课听不懂,下课泪两行. 有的人什么套路都会,我.. 只能可怜巴巴的抄代码,然后自己总结,顺(zhu)便(yao)颓博客 1.递推dp的思路做到一半死了,怎么也想不出来如何处理 ...

  2. 一道超级坑爹的水题(ACdream oj 无耻的出题人)

     A - 无耻的出题人 Time Limit: 2000/1000 MS (Java/Others)      Memory Limit: 65536/32768 KB (Java/Others) ...

  3. 一道区间DP的水题 -- luogu P2858 [USACO06FEB]奶牛零食Treats for the Cows

    https://www.luogu.org/problemnew/show/P2858 方程很好想,关键我多枚举了一次(不过也没多大关系) #include <bits/stdc++.h> ...

  4. HDU 2674 N!Again(数学思维水题)

    题目 //行开始看被吓一跳,那么大,没有头绪, //看了解题报告,发现这是一道大大大的水题,,,,,//2009 = 7 * 7 * 41//对2009分解,看它有哪些质因子,它最大的质因子是41,那 ...

  5. SRM 584 第一次玩TopCoder。。。只水题一道。。。

    第一次topcoder,以前老感觉没有资格去做tc,cf什么的,现在已经慢慢接触了. 感觉还可以,还是有让我们这些蒻菜安慰的水题. tc的确很好玩,用客户端比赛,还有各种规则,而且还是只编写一个类提交 ...

  6. 一道cf水题再加两道紫薯题的感悟

    . 遇到一个很大的数除以另一个数时,可以尝试把这个很大的数进行,素数因子分解. . 遇到多个数的乘积与另一个数的除法时,求是否能整除,可以先求每一个数与分母的最大公约数,最后若分母数字为1,则证明可整 ...

  7. 做了一道cf水题

    被一道cf水题卡了半天的时间,主要原因时自己不熟悉c++stl库的函数,本来一个可以用库解决的问题,我用c语言模拟了那个函数半天,结果还超时了. 题意大概就是,给定n个数,查询k次,每次查询过后,输出 ...

  8. ny525 一道水题

    一道水题时间限制:1000 ms  |  内存限制:65535 KB 难度:2描述 今天LZQ在玩一种小游戏,但是这游戏数有一点点的大,他一个人玩的累,想多拉一些人进来帮帮他,你能写一个程序帮帮他吗? ...

  9. NYOJ-525一道水题思路及详解

    一道水题 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述 今天LZQ在玩一种小游戏,但是这游戏数有一点点的大,他一个人玩的累,想多拉一些人进来帮帮他,你能写一个程序帮帮他 ...

随机推荐

  1. vue-cli3 中的环境变量

    官方文档是这样写的: src同名文件夹下的建立 .env.[model] 配置文件  // mode:production development ... 载入的变量会对vue-cli-service ...

  2. centos 7中 yum安装jdk

    yum安装jdk的好处就是不需要手动再配置环境变量,所有的变量都是自动生成 1.检查系统是否存在jdk,存在删除原版jdk 如果没有信息输出,则表示没有安装jdk rpm -qa |grep java ...

  3. Django REST framework - 版本控制

    目录 Django REST framework 版本控制 为什么需要版本控制 DRF提供了5种版本控制方案 版本控制系统的使用 全局配置 局部配置 获取版本信息 Django REST framew ...

  4. 【Codeforces 459D】Pashmak and Parmida's problem

    [链接] 我是链接,点我呀:) [题意] 定义两个函数 f和g f(i)表示a[1..i]中等于a[i]的数字的个数 g(i)表示a[i..n]中等于a[i]的数字的个数 让你求出来(i,j) 这里i ...

  5. 【郑轻邀请赛 B】base64解密

    [题目链接]:https://acm.zzuli.edu.cn/zzuliacm/problem.php?id=2128 [题意] [题解] 把密文; 在表中找到每个字符对应的数字; 然后转换成相应的 ...

  6. 相同的雪花 Hash

    相同的雪花 时间限制:1000 ms  |  内存限制:65535 KB 难度:4   描述 You may have heard that no two snowflakes are alike. ...

  7. [bzoj4154][Ipsc2015]Generating Synergy_KD-Tree_dfs序

    Generating Synergy bzoj-4154 Ipsc-2015 题目大意:给定一棵n个节点树,m个操作,支持:将一个点周围所有距该点距离不超过l的子结点的颜色改成另一种颜色:查询单点颜色 ...

  8. Spring MVC 一次简单的 CRUD

    基本环境搭建 1.数据库 和 实体类 的名字相同,实体类 属性名即 数据库 字段名. 2.创建 实体类 对应 dao 类,持久层框架 mybatis 正处于学习中,这里就用原始的 jdbc 操作了. ...

  9. A*算法学习(转)

    A*启发式搜索算法详解 人工智能 1导言 1.1 算法 1.2 Dijkstra算法与最佳优先搜索 1.3 A*算法 2 启发式算法 2.1 A*对启发式函数的使用 2.2 速度还是精确度? 2.3  ...

  10. cppunit 的使用

    原文: http://blog.csdn.net/abcdef0966/article/details/5699248