ACdream 1188 Read Phone Number(字符串:模拟)
2014-08-29 21:13
489 查看
Read Phone Number
Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others)SubmitStatisticNext
Problem
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 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 isthe 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
Source
codejam
Manager
KIDxSubmitStatistic
刚看到这个题真是吓尿了。。。
好复杂的样子,但其实并不怎么难,一步一步写就好了
因为写的比较着急,所以变量名命名不太好,凑合着看吧
代码如下:
#include <bits/stdc++.h> #define MAXN 120 using namespace std; int num[MAXN]; char phone[MAXN], format[MAXN], chs[MAXN]; char s2[][20] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; char s1[][20] = {"zero", "one", "double", "triple", "quadruple", "quintuple", "sextuple", "septuple", "octuple", "nonuple", "decuple"}; void print(char str[]) { int end = strlen(str); int start = 0; // printf("str = %s\n", str); while(start < end) { int cnt = 1; for(int i=start; i<end; ++i) { if(str[i] == str[i+1]) { ++cnt; } else break; } if(cnt > 1 && cnt<=10) { printf(" %s", s1[cnt]); printf(" %s", s2[str[start]-'0']); } else if(cnt == 1) { printf(" %s", s2[str[start]-'0']); } else if(cnt > 10) { for(int j=0; j<cnt; ++j) printf(" %s", s2[str[start]-'0']); } start += cnt; } } int main(void) { int n, len_format, len_phone, cnt, begin, tmp; scanf("%d", &n); for(int t=1; t<=n; ++t) { scanf("%s", phone); len_phone = strlen(phone); tmp = cnt = 0; while(tmp < len_phone) { scanf("%d", &num[cnt]); getchar(); tmp += num[cnt]; ++cnt; } //printf("cnt = %d\n", cnt); begin = 0; printf("Case #%d:", t); for(int i=0; i<cnt; ++i) { memset(chs, 0, sizeof(chs)); strncpy(chs, phone+begin, num[i]); begin += num[i]; print(chs); //printf("chs = %s\n", chs); } puts(""); } return 0; }
相关文章推荐
- ACdream 1188 Read Phone Number (字符串大模拟)
- HDU 5611 Baby Ming and phone number(字符串模拟)
- Problem A. Read Phone Number -模拟读电话号码
- Problem A. Read Phone Number
- Google of Greater China Test for New Grads of 2014---很水的一道题Problem A. Read Phone Number
- hdoj--5611--Baby Ming and phone number(模拟水题)
- 1016. Phone Bills (25) 字符串处理,时间模拟, 特殊情况判断
- Leetcode: LetterCombinationsofaPhoneNumber 根据手机按键,给出所有可能的字符串
- Round A China New Grad Test 2014 Problem A. Read Phone Number
- HDU-5611 Baby Ming and phone number(模拟)
- Google中国2014校园招聘笔试Round A China New Grad Test Problem A. Read Phone Number
- acdream 1188 telephone number 模拟
- [LeetCode]-Letter Combinations of a Phone Number 电话键盘的字符串组合
- hdu 5611 Baby Ming and phone number(模拟)
- BestCoder Round #69 (div.2)-Baby Ming and phone number(模拟)
- Read Phone Number
- 【HDU1409】【模拟 极端数据特判】Is It a Number 判定给定字符串是否为数类型
- Read Phone Number
- HDOJ 5611-Baby Ming and phone number【模拟】
- hdoj--5611--Baby Ming and phone number(模拟水题)