ACM_一道耗时间的水题

一道耗时间的水题

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代码:
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int maxn = 105;//因为字符串s2中可能会出现100个‘1‘,所以这里取105
 4 const string str1[]={"decuple","","double","triple","quadruple","quintuple","sextuple","septuple","octuple","nonuple"};
 5 const string str2[]={"zero","one","two","three","four","five","six","seven","eight","nine"};
 6 int t,n,k,x,s[maxn],e[maxn];string s1,s2,tp[maxn];//s数组记录截取字符串s1的起始位置,e数组记录截取字符的个数
 7 int main(){
 8     cin>>t;getchar();//吃掉回车符对字符串的影响
 9     for(int i=1;i<=t;++i){
10         cin>>s1>>s2;s[0]=k=x=0;//s[0]起始位置为0,k记录分成子串的个数
11         cout<<"Case #"<<i<<":";
12         for(unsigned int j=0;j<=s2.length();++j){
13             if(s2[j]==‘-‘||s2[j]==‘\0‘){e[k++]=x;x=0;}
14             else x=x*10+s2[j]-‘0‘;
15         }
16         for(int j=0;j<k;++j)s[j+1]=s[j]+e[j];//累加起始位置
17         for(int j=0;j<k;++j)tp[j]=s1.substr(s[j],e[j]);//获得对应子串
18         for(int j=0;j<k;++j){n=1;//n记录相同元素的个数,初始值为1
19             for(unsigned int h=0;h<tp[j].length();++h){
20                 if(tp[j][h]!=tp[j][h+1]){
21                     if(1<n&&n<=10)cout<<" "+str1[n%10];//取余操作
22                     if(n<=10)cout<<" "+str2[tp[j][h]-‘0‘];
23                     else{//n大于10,则输出n个对应的字符串
24                         for(int m=1;m<=n;++m)
25                             cout<<" "+str2[tp[j][h]-‘0‘];
26                     }n=1;//n重置为1
27                 }
28                 else n++;//相同个数加1
29             }
30         }
31         cout<<endl;
32     }
33     return 0;
34 }


原文地址:https://www.cnblogs.com/acgoto/p/9219887.html

时间: 2024-08-04 20:21:37

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

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

 A - 无耻的出题人 Time Limit: 2000/1000 MS (Java/Others)      Memory Limit: 65536/32768 KB (Java/Others) Submit Status Problem Description 听到X神要参加比赛,只会Fibnacci数的出题人被吓得哭晕在厕所.为了防止X神AK(ALL KILL)比赛题目,无耻的出题人只好在题面上做些手脚(加密).其中一道题的题目描述如下: hjxh dwh v vxxpde,mmo i

POJ 2328 Guessing Game(一道让我想哭的水题!)

[题意简述]:就是猜数,我想大家一定会在电视上看过这样类似的节目. [分析]:WA到死,本来就应该是一道简单的水题,但是由于我本人也很水,在控制字符的输入上有了点小问题,所以做了很久!想的也有点杂,有点多!还是题做得少. 这个是我WA到死的代码!! // WA 代码!! #include<iostream> #include<cstring> using namespace std; int main() { int a; char ans[10]; while(1) { bool

一道字符串水题LSS(ACdream)

一道水题但是我错了好惨 罚时罚到最后一名 Problem Description Time flies, four years passed, colleage is over. When I am about to leave, a xuemei ask me an ACM  problem, but I can't solve it, I am 功力尽失.  Please help me so that I won't lose face in front of xuemei! Give y

ACM_输出格式(水题)

输出格式 Time Limit: 2000/1000ms (Java/Others) Problem Description: 某水比参加了XX杯,但是他太水,所以三等都木有,所以他决定出一道水题水一水. Input: 输入多组测试数据,每一组一个整数width(3-50),一个整数height(3-50),一个字符串(长度不超过width-2). Output: 对于每个测试实例,要求把字符串按要求输出(字符串处于由width为长,height为宽的矩形的中部), (...倘若不能完全对称,请

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

1. 遇到一个很大的数除以另一个数时,可以尝试把这个很大的数进行,素数因子分解. 2. 遇到多个数的乘积与另一个数的除法时,求是否能整除,可以先求每一个数与分母的最大公约数,最后若分母数字为1,则证明可整除.或者把分子上的每个数进行素数因子分解,分母上的数也进行素数因子分解,若分子上的与分母上相同素数因子进行比较,分子上的素数因子指数大于分母位置上的,则证明可整除. 3. 遇到乘法的时候注意越界问题. 4. 遇到求某一个区间内,满足某一特征的数的个数,而这个特征与因子,约数有关,尝试用埃筛的方法

碰到日期题就怕的我来写一道水题吧

HDOJ-2005, http://acm.hdu.edu.cn/showproblem.php?pid=2005 20XX系列的水题哈哈,写了二十分钟,就为找到一种比较正常不傻逼的写法... 嗯,学习了一下,闰年的判断可以写成一个接受参数的宏. #define lev(n) (n%4==0&&(n%100!=0||n%400==0)) 然后建立一个二维数组来存储闰年和非闰年的每月天数. int calendar[2][13] = { {0,31,28,31,30,31,30,31,31,

ACM_水题你信吗

水题你信吗 Time Limit: 2000/1000ms (Java/Others) Problem Description: 某发最近又认识了很多妹(han)子,可是妹(han)子一多不免有时会忘记那么一两个,为了记得他们的名字,发哥设计了一个记录器.对于每个他刚认识的妹(han)子,他都把妹子的名字放进记录器里,如果记录器已经有这个妹子的名字,则在这个妹子的名字后面加上一个数字(数字从1开始),输出妹子的名字加上数字.若记录器没有这个妹子的记录,则输出OH GOD. Input: (EOF

nyist oj 540 奇怪的排序(水题)

奇怪的排序 时间限制:1000 ms  |  内存限制:65535 KB 难度:1 描述 最近,Dr. Kong 新设计一个机器人Bill.这台机器人很聪明,会做许多事情.惟独对自然数的理解与人类不一样,它是从右往左读数.比如,它看到123时,会理解成321.让它比较23与15哪一个大,它说15大.原因是它的大脑会以为是32与51在进行比较.再比如让它比较29与30,它说29大. 给定Bill两个自然数A和B,让它将 [A,B] 区间中的所有数按从小到大排序出来.你会认为它如何排序? 输入 第一

CYJian的水题大赛

实在没忍住就去打比赛了然后一耗就是一天 最后Rank19还是挺好的(要不是乐多赛不然炸飞),这是唯一一套在Luogu上号称水题大赛的而实际上真的是水题大赛的比赛 好了我们开始看题 T1 八百标兵奔北坡 首先看到这道题你要先仔细想一想切比雪夫距离是什么 我们更加形象地理解一下就会知道这是一个等腰三角形(算了还是看图吧,对于红色的格子,所有黄色的格子对于它都在北面): 然后仔细看一下就发现每一个点可以设计一个DP的思想(类似于过河卒): \(f_{i,j}=0(if\ (i,j)\ is\ a\ m