Read Phone Number
2013-09-23 12:31
99 查看
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.
one or more positive integers separated by dashes (-), without leading zeros and whose sum always equals the number of digits in the phone number.
实现代码:
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 |
#include "stdio.h" #include "iostream" using namespace std; #define MAX_T 100 #define MAX_SMA_N 10 #define MAX_LAG_N 100 char English[][10] = {"zero","one","two","three","four","five","six","serven","eight","nine"}; char same_Num[][20]= {" "," ","double","triple","quadruple","quintuple", "sextuple","setptule","octuple","nonuple","decuple"}; void main() { int In_T; cin >> In_T; //** 换行 char PhoneNum[MAX_T][MAX_LAG_N]; char FromeNum[MAX_T][MAX_LAG_N]; for (int i=0 ;i < In_T ;i++) { cin >> PhoneNum[i]; cin >> FromeNum[i]; } //*** 对输入信息进行处理分析 for(int j = 0; j < In_T; j++) { cout << "Case #" << j+1 <<":"; int ch_flag =0; int kk = 0; while (FromeNum[j][ch_flag] != NULL && FromeNum[j][ch_flag] != '\n') { if(FromeNum[j][ch_flag] == '-') { ch_flag++; continue; } int k =0; int Num_State = FromeNum[j][ch_flag] -'0'; //*** 统计相同过个数 int Same_Num = 1; while(k < Num_State-1) { if (PhoneNum[j][k+kk] == PhoneNum[j][kk+k+1]) { k++; //** 相等指针后移 Same_Num++; if(k == Num_State-1) { if (Same_Num != 1) { cout<< same_Num[Same_Num] <<" "; } cout<< English[PhoneNum[j][k+kk]-'0'] <<" "; Same_Num = 1; } } else { if (Same_Num != 1) { cout<< same_Num[Same_Num] <<" "; } cout<< English[PhoneNum[j][k+kk]-'0'] <<" "; k++; if(k == Num_State-1) { cout<< English[PhoneNum[j][k+kk]-'0'] <<" "; } Same_Num = 1; } } kk += FromeNum[j][ch_flag] -'0'; ch_flag ++; } cout <<endl; } system("pause"); return; }
相关文章推荐
- Problem A. Read Phone Number
- Google中国2014校园招聘笔试Round A China New Grad Test Problem A. Read Phone Number
- ACdream 1188 Read Phone Number(字符串:模拟)
- Read Phone Number
- Round A China New Grad Test 2014 Problem A. Read Phone Number
- Read Phone Number
- 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
- Problem A. Read Phone Number -模拟读电话号码
- Read Phone Number
- LeetCode Letter Combinations of a Phone Number
- BestCoder Round #69 (div.2) B HDOJ5611 Baby Ming and phone number(stl)
- leetcode --17. Letter Combinations of a Phone Number
- LeetCode 之 Letter Combinations of a Phone Number
- Letter Combinations of a Phone Number
- hdoj--5611--Baby Ming and phone number(模拟水题)
- Java [leetcode 17]Letter Combinations of a Phone Number
- Leetcode题解-17. Letter Combinations of a Phone Number
- android Settings中About Phone的Model number等信息的修改