Google of Greater China Test for New Grads of 2014---很水的一道题Problem A. Read Phone Number
来源:互联网 发布:mac如何共享桌面文件 编辑:程序博客网 时间:2024/05/23 19:41
Problem
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.T lines|test cases follow. Each line contains a phone number N and the dividing format F, one or more positive integers separated by dashes (-), without leading 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.
Limits
1 ≤ T ≤ 100.
Small dataset
1 ≤ length of N ≤ 10.
Large dataset
1 ≤ length of N ≤ 100.
Sample
Input
315012233444 3-4-415012233444 3-3-512223 2-3
Output
Case #1: one five zero one double two three three triple fourCase #2: one five zero one double two double three triple fourCase #3: one two double two three
#include<iostream>#include<string>#include<vector>using namespace std;string shu[10]={"zero","one","two","three","four","five","six","seven","eight","nine"};string coun[9]={"double","triple","quadruple","quintuple","sextuple","septuple","octuple","nonuple","decuple"};int main(){freopen("D:\\A-small-practice.in","r",stdin);freopen("D:\\A-small-practice.out","w",stdout);/**********************************************/int T,id;cin>>T;id=1;while(T--){vector<string> xiao;//保存分割后的子段 vector<int> fen;//保存每个段的长度string n,f;cin>>n>>f;int i=0; while(i<f.size()){int j;j=f.find_first_of('-',i);j=(j==-1)?(f.size()):j;string temp=f.substr(i,j-i);int temp_i=atoi(temp.c_str());fen.push_back(temp_i);i=j+1;}int j=0;for(i=0;i<fen.size();i++){string temp=n.substr(j,fen[i]);xiao.push_back(temp);j=fen[i]+j;}vector<int> shuzi;//记录单个的数字vector<int> count;//对应数字出现的次数for(i=0;i<xiao.size();i++){for(int k=0;k<xiao[i].size();k++){shuzi.push_back(xiao[i][k]-'0');int c=1;while(xiao[i][k]==xiao[i][k+c]&&k+c<xiao[i].size()){c++;}count.push_back(c);k=k+c-1;}}cout<<"Case #"<<id<<": ";for(i=0;i<shuzi.size();i++){if(count[i]>1&&count[i]<11)cout<<coun[count[i]-2]<<" "<<shu[shuzi[i]]<<" ";else if(count[i]>10) for(int cc=0;cc<count[i];cc++)cout<<shu[shuzi[i]]<<" ";elsecout<<shu[shuzi[i]]<<" ";}cout<<endl;id++;}/***********************************************/ fclose(stdin);fclose(stdout);return 0;}
- Google of Greater China Test for New Grads of 2014---很水的一道题Problem A. Read Phone Number
- Google of Greater China Test for New Grads of 2014 Round A 第2题
- Google中国2014校园招聘笔试Round A China New Grad Test Problem A. Read Phone Number
- Round A China New Grad Test 2014 Problem A. Read Phone Number
- Round A China New Grad Test 2014---很基本的一道题Problem B. Rational Number Tree
- Read Phone Number - Round A China New Grad Test 2014 - 循环控制
- Google China New Grad Test 2014 Round A Problem A
- Google China New Grad Test 2014 Round A Problem B
- Google China New Grad Test 2014 Round A Problem C
- Google China New Grad Test 2014 Round A Problem D
- Google China New Grad Test 2014 Round A Problem E
- Google中国2014校园招聘笔试Round A China New Grad Test Problem B. Rational Number Tree
- Google中国2014校园招聘笔试Round A China New Grad Test Problem E. Spaceship Defence
- Problem A. Read Phone Number
- Problem A. Read Phone Number
- Round A China New Grad Test 2014 Problem C. Sorting
- Problem C. Sorting---Round A China New Grad Test 2014
- 【一天一道LeetCode】#17. Letter Combinations of a Phone Number
- slf4j和log4j配置
- App攻略:一篇文章看懂线下预装市场
- 读取配置文件神器 -----ResourceBundle 介绍
- Spring MVC beginner tutorial with Spring Tool Suite IDE
- TestComplete总结六
- Google of Greater China Test for New Grads of 2014---很水的一道题Problem A. Read Phone Number
- hdu 2206 IP的计算
- 【jQuery】用jQuery给文本框添加只读属性【readOnly】
- Java学习笔记<3>面向对象相关
- 我退役了
- jsp中常用的EL表达式fn:spilt,将\r\n替换成<br/>
- ViewPager设置 缓存个数、页卡间距、数据更新
- Gdb多线程调试技术
- numpy简明教程(2)