一道耗时间的水题

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. (5.2.1)配置服务器参数——即时文件初始化(IFI)

    关键词:零填充,即时文件初始化 转自:https://www.cnblogs.com/gaizai/p/3516905.html 概念: 所有新申请的空间,sql server都要以0来填充完磁盘文件 ...

  2. 不抛异常的swap函数

    namespace AStuff{ template<typename T> class A { public: void swap(A *other) { using std::swap ...

  3. win10下VMware Workstation 14运行虚拟机黑屏

    最新 升级电脑Win10自动升级后,在打开虚拟机后,很卡,且出现黑屏,但是挂起后仍能显示锁屏界面,网上就一顿搜.下面放解决方法. 管理员运行 netsh winsock reset 帮你解决一切烦恼. ...

  4. _initialize() 区别 __construct()

    _initialize()方法是在任何方法执行之前,都要执行的,当然也包括 __construct构造函数. 也就是说如果存在_initialize()函数,调用对象的任何方法都会导致_initial ...

  5. Python编程时.py与.pyc文件的介绍

    Python的程序中,是把原始程序代码放在.py文件里,而Python会在执行.py文件的时候.将.py形式的程序编译成中间式文件(byte-compiled)的.pyc文件,这么做的目的就是为了加快 ...

  6. Python模块 os.walk

    Os.walk os.walk(top,topdown=True,onerror=None,followlinks=False) os.walk()是python中内置(built-in)的目录树生成 ...

  7. 第七节:pandas排序

    pandas具有两种排序方式:sort_index()和sort_values().

  8. ES6-babel转码

    关于BaBel转码 有人问我babel的功能以及执行的过程和配置,在网上查阅了大量的资料~收集到这些~有错请指出,及时修改. ------------------------------------- ...

  9. 【[Offer收割]编程练习赛13 B】最大子矩阵(自己的思路)

    [题目链接]:http://hihocoder.com/contest/offers13/problem/2 [题意] [题解] 算出1..250*250这些数字每个数字的所有因子(成对的那种,即x* ...

  10. IDEA 工具使用报错总结

    读前语:此文章仅给非入门级观看 1.使用Debug  无法运行,而使用Run 则正常启动,报错代码如下 1 Error running 'jx_web': Unable to open debugge ...