一道耗时间的水题

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. PHP常用的设计模式

    工厂模式 工厂模式是我们最常用的实例化对象模式,是用工厂方法代替new操作的一种模式. 使用工厂模式的好处是如果你想要更改所实例化的类名等,则只需要更改该工厂方法内容即可,不需逐一寻找代码中具体实例化 ...

  2. 8.2.3 覆写 Equals

    经过对四种不同类型判等方法的讨论,我们不难发现不管是 Equals 静态方法.Equals 虚方法 抑或==操作符的执行结果,都可能受到覆写 Equals 方法的影响.因此研究对象判等就必须将注意 力 ...

  3. Silverlight之我见——DataGrid数据验证

    <UserControl x:Class="DataValidationSample.MainPage" xmlns="http://schemas.microso ...

  4. 联想小新Air 15 安装黑苹果macOS High Sierra 10.13.6过程

    联想小新Air 15 安装黑苹果全过程 本文参考:https://blog.csdn.net/qq_28735663/article/details/80634300 本人是联想小新AIr 15 , ...

  5. 《零压力学Python》 之 第二章知识点归纳

    第二章(数字)知识点归纳 要生成非常大的数字,最简单的办法是使用幂运算符,它由两个星号( ** )组成. 如: 在Python中,整数是绝对精确的,这意味着不管它多大,加上1后都将得到一个新的值.你将 ...

  6. nyoj_33_蛇形填数_201308221636

    蛇形填数时间限制:3000 ms  |  内存限制:65535 KB 难度:3描述 在n*n方陈里填入1,2,...,n*n,要求填成蛇形.例如n=4时方陈为:10 11 12 19 16 13 28 ...

  7. MVC.Net 5:允许保存和输出Html内容

    当我们在保存表单内容时,如果其中有一项内容包含Html的tag时,系统会报如下错误: A potentially dangerous Request.Form value was detected f ...

  8. mvn 仓库

    http://mvnrepository.com/artifact/org.postgresql/postgresql/9.3-1103-jdbc41 ------------------------ ...

  9. [Debug] Use Remote Sources to Debug a Web App on an Emulator, Simulator, or Physical Device

    We can emulate different operating systems, browsers, and devices within a desktop operating system. ...

  10. HDU 2206 IP的计算(字符串处理)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2206 Problem Description 在网络课程上,我学到了非常多有关IP的知识. IP全称叫 ...