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代码:
#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_一道耗时间的水题的更多相关文章
- 关于一道你们眼中的水题 Windy数 的乱写(数位dp)
啊一道水题有什么好说的 上课听不懂,下课泪两行. 有的人什么套路都会,我.. 只能可怜巴巴的抄代码,然后自己总结,顺(zhu)便(yao)颓博客 1.递推dp的思路做到一半死了,怎么也想不出来如何处理 ...
- 一道超级坑爹的水题(ACdream oj 无耻的出题人)
A - 无耻的出题人 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 KB (Java/Others) ...
- 一道区间DP的水题 -- luogu P2858 [USACO06FEB]奶牛零食Treats for the Cows
https://www.luogu.org/problemnew/show/P2858 方程很好想,关键我多枚举了一次(不过也没多大关系) #include <bits/stdc++.h> ...
- HDU 2674 N!Again(数学思维水题)
题目 //行开始看被吓一跳,那么大,没有头绪, //看了解题报告,发现这是一道大大大的水题,,,,,//2009 = 7 * 7 * 41//对2009分解,看它有哪些质因子,它最大的质因子是41,那 ...
- SRM 584 第一次玩TopCoder。。。只水题一道。。。
第一次topcoder,以前老感觉没有资格去做tc,cf什么的,现在已经慢慢接触了. 感觉还可以,还是有让我们这些蒻菜安慰的水题. tc的确很好玩,用客户端比赛,还有各种规则,而且还是只编写一个类提交 ...
- 一道cf水题再加两道紫薯题的感悟
. 遇到一个很大的数除以另一个数时,可以尝试把这个很大的数进行,素数因子分解. . 遇到多个数的乘积与另一个数的除法时,求是否能整除,可以先求每一个数与分母的最大公约数,最后若分母数字为1,则证明可整 ...
- 做了一道cf水题
被一道cf水题卡了半天的时间,主要原因时自己不熟悉c++stl库的函数,本来一个可以用库解决的问题,我用c语言模拟了那个函数半天,结果还超时了. 题意大概就是,给定n个数,查询k次,每次查询过后,输出 ...
- ny525 一道水题
一道水题时间限制:1000 ms | 内存限制:65535 KB 难度:2描述 今天LZQ在玩一种小游戏,但是这游戏数有一点点的大,他一个人玩的累,想多拉一些人进来帮帮他,你能写一个程序帮帮他吗? ...
- NYOJ-525一道水题思路及详解
一道水题 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 今天LZQ在玩一种小游戏,但是这游戏数有一点点的大,他一个人玩的累,想多拉一些人进来帮帮他,你能写一个程序帮帮他 ...
随机推荐
- react 子组件调用父组件方法
import React from 'react'import '../page1/header.css'import { Table } from 'antd'import Child from ' ...
- 洛谷——P1183 多边形的面积
P1183 多边形的面积 多边形求面积公式: $\frac {\sum_{i=0}^{n-1}(x_iy_{i+1}-y_ix_{i+1})}{2}$ #include<bits/stdc++. ...
- Django——11 状态保持 form表单 登陆注册样例
Django 状态保持 用户状态例子 实现注册登陆实例 django forms 表单的使用 注册功能 登陆功能 状态保持cookie和session 1.http协议是无状态的:每次请求都是一次 ...
- GeoTrust 企业(OV)型 多域名(SAN/UC)版 SSL证书
GeoTrust 企业(OV)型 多域名(SAN/UC)版 SSL证书(GeoTrust True BusinessID With Multi-Domain(SAN/UC) ),支持多域名,属于企业 ...
- fzu 2122
#include<stdio.h> #include<string.h> #define N 51000 char s1[200],s2[200],s[N]; int main ...
- spring-cloud-feign使用@RequetParam错误:QueryMap parameter must be a Map: int
错误: QueryMap parameter must be a Map: int spring-cloud-feign处理@RequestParam和Spring MVC的不一样,Spring MV ...
- oracle latch
(转载 : http://www.dbtan.com/2010/05/latch-free.html) Latch Free(闩锁释放):Latch Free通常被称为闩锁释放,这个名称常常引起误解, ...
- [数据结构与算法]排序算法(Python)
1.直接插入排序 给定一个数组后,从第二个元素开始,如果比第一个小,就跟他交换位置,否则不动:第三个元素如果比第二个小,把第三个跟第二个交换位置,在把第二个与第一个比较:..... def inser ...
- Android:创建无标题栏的Activity
上图是一个带标题栏的Activity.有些时候我们希望能去除这个标题栏,做法如下: 1. 在res/values目录下面创建styles.xml.如果你已经有这个文件了,那么直接打开这个文件,添加如下 ...
- Linux/CentOS各种服务框架的搭建完整流程
在2012年的时候,由于要照应新人对Linux以及相关服务的了解和学习,我特地把当时我们创业项目的全部服务搭建过程写成了一篇文档,能够让他们学习而且有所參照. 以下就以这篇文档为底稿,进行一些改动和敏 ...