Problem A. Read Phone Number -模拟读电话号码
2013-09-23 13:45
204 查看
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 | |
3 15012233444 3-4-4 15012233444 3-3-5 12223 2-3 | |
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 |
来源:https://code.google.com/codejam/contest/2924486/dashboard#s=p0
这到题要求按习惯读电话号码。
相同的数要连着一起读。超过10个,就分为一个一个的读。
问题比较明确,划分清功能函数模拟即可。
#include<iostream> #include<stdio.h> #include<stdlib.h> #include<string.h> #include<vector> #include<stack> #include<algorithm> #include<math.h> using namespace std; const int N=110; //freopen("a.in", "r", stdin); //freopen("a.out", "w", stdout); char *s_num[10]={"zero","one","two","three","four","five","six","seven","eight","nine"}; char *t_num[11] = {"error","error","double","triple","quadruple","quintuple","sextuple","septuple","octuple","nonuple","decuple"}; void print_num(const char *s,int len){ int i,j,count; i=0;j=0; while(i<len){ count=1; j=i+1; char tmp=s[i]; while(j<len&&s[j]==tmp){ count++; j++; } if(count<=1){ printf(" %s",s_num[tmp-'0']); } else if(count>1&&count<=10) printf(" %s %s",t_num[count],s_num[tmp-'0']); else{ int k; for(k=i;k<count;k++) printf(" %s",s_num[tmp-'0']); } i=j; } } int main() { freopen("a.in", "r", stdin); freopen("a.out", "w", stdout); int t; scanf("%d",&t); int caseid; char num ; for(caseid=1;caseid<=t;caseid++){ scanf("%s",num); int len_s=strlen(num); int sum=0; vector<int> sep; while(sum<len_s){ int tmp_a; scanf("%d-",&tmp_a); sep.push_back(tmp_a); sum+=tmp_a; } int i=0; int seq_len=0; printf("Case #%d: ",caseid); for(i=0;i<sep.size();i++){ print_num(num+seq_len,sep[i]); seq_len+=sep[i]; } printf("\n"); } }
相关文章推荐
- Round A China New Grad Test 2014 Problem A. Read Phone Number
- ACdream 1188 Read Phone Number (字符串大模拟)
- Problem A. Read Phone Number
- Problem A. Read Phone Number
- Google中国2014校园招聘笔试Round A China New Grad Test Problem A. Read Phone Number
- ACdream 1188 Read Phone Number(字符串:模拟)
- Google of Greater China Test for New Grads of 2014---很水的一道题Problem A. Read Phone Number
- HDU-5611 Baby Ming and phone number(模拟)
- hdu 5611 Baby Ming and phone number(模拟)
- lintcode 中等题:Letter Combinations of a Phone Number 电话号码的字母组合
- hdoj--5611--Baby Ming and phone number(模拟水题)
- BestCoder Round #69 (div.2)-Baby Ming and phone number(模拟)
- LeetCode-Letter Combinations of a Phone Number-电话号码字母组合-DFS
- hdoj--5611--Baby Ming and phone number(模拟水题)
- LeetCode Letter Combinations of a Phone Number 电话号码组合
- 17:Letter Combinations of a Phone Number(字母组合的电话号码)
- HDU 5611 Baby Ming and phone number(字符串模拟)
- [LeetCode] Letter Combinations of a Phone Number 电话号码的字母组合
- 使用PhoneNumberValidator判断用户输入的电话格式,并用PhoneFormatter对电话号码格式化。
- POJ1350 Cabric Number Problem [模拟]