google jam 比赛题(设计有问题)
题目:
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.
翻译:
问题 你知道如何阅读英语中的电话号码吗?现在让我告诉你。 例如,在中国,电话号码是11位数字,如: 15012233444 。有人将号码为3-4-4格式,即150 1223 3444 。虽然有人将号码为3-3-5格式,即150 122 3344 4 。不同的格式,导致不同的方式来读取这些数字: 150 1223 3444读一五零壹双三三四个。 150 122 3344 4读取一五零壹双双三三四个。 可是问题来了: 鉴于电话号码和除以格式的列表,输出正确的方式来阅读这些数字。 规则: 单数刚读它们分开。 2连续使用双。 连续3使用三倍。 4连续使用翻两番。 5连续使用五倍。 6连续使用六倍。 7连续使用七元。 连续使用8八倍。 连续使用9 nonuple 。 连续十数十倍。 超过10个连续的数字阅读他们都分开。 输入 输入的第一行给出了测试用例的数量, T. T线|测试用例遵循。每行包含一个电话号码N和除以格式F,破折号( - )分隔的一个或多个正整数,不带前导零的总和总是等于数字位数的电话号码。 产量 对于每个测试用例,输出一行包含“案例# X:Y ”,其中x是案件编号(从1开始)和y是阅读英语句子中的字是由空格分隔。 范围 1≤T≤ 100。 小数据集 1长度≤ N ≤ 10 。 大数据集 1长度≤ N ≤ 100 。
google_number_reader.py
#!/usr/bin/env python
NUMBER=("ZERO","ONE","TWO","THERR","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE","TEN")
REPT_COUNT=("","double","triple","quadruple","quintuple",
"sextuple","septuple","octuple","nonuple","decuple")
class PhoneNumberReader:
def set_piece_list(self,list):
i = 0
sum = 0
flag_list = [0]
while i < len(list):
sum += int(list[i])
flag_list.append(sum)
i += 1
return flag_list
def cut(self,phone,flag_list):
i = 0
piece_list = []
while i < len(flag_list) - 1:
piece_list.append(phone[flag_list[i]:flag_list[i+1]])
i += 1
return piece_list
def read_piece(self,a_piece):
word_list = []
s_index = 0
repetitions = 0
cur_char = ""
while True:
if s_index == len(a_piece):
break
cur_char = int(a_piece[s_index])
if s_index + 1 < len(a_piece) and a_piece[s_index] == a_piece[s_index + 1]:
repetitions += 1
s_index += 1
continue
if len(REPT_COUNT[repetitions]) > 0:
word_list.append(REPT_COUNT[repetitions])
word_list.append(NUMBER[cur_char])
repetitions = 0
s_index += 1
return word_list
def read_piece_list(self,piece_list):
word_list = []
for i in piece_list:
word_list += self.read_piece(i)
s = ""
for i in word_list:
s += i + " "
return s[:-1]
def read(self,line):
try:
phone,format = line.split(" ")
format_list = format.split("-")
flag_list = self.set_piece_list(format_list)
piece_list = self.cut(phone,flag_list)
return self.read_piece_list(piece_list)
except ValueError:
print line
if __name__ == '__main__':
try:
datafile = open("A-large-practice.in","r")
phone_reader = PhoneNumberReader()
while True:
line = datafile.readline()
if not line:
break
phone_reader.read(line)
except IOError, e:
print e.strerror
test_google_number_reader.py
#!/usr/bin/env python from phone_number_reader import PhoneNumberReader
import unittest class TestPhoneNumberReader(unittest.TestCase):
def setUp(self):
self.phone_number_reader = PhoneNumberReader() def test_344(self):
s = self.phone_number_reader.read("15810665042 3-4-4")
print s
assert(s == "ONE FIVE EIGHT ONE ZERO double SIX FIVE ZERO FOUR TWO")
#def test_443(self):
# self.phone_number_reader.read("15810665042 4-4-3") #def test_353(self):
# self.phone_number_reader.read("15810665042 3-5-3") #def test_353(self):
# self.phone_number_reader.read("15810665042 3-5-3") if __name__ == '__main__':
unittest.main()
google jam 比赛题(设计有问题)的更多相关文章
- 25条来自 Google 的移动网站设计准则
越来越的用于通过移动设备访问网络,因此对于企业来说,现在比以往任何时候都更需要一个移动网站.但是,怎么样才能制作一个优秀的移动网站呢? 为了回答这个问题,Google 与 AnswerLab 合作,研 ...
- 实验楼的php比赛题,网页数据提取。
实验楼的php比赛题,网页数据提取. 题目的地址:https://www.shiyanlou.com/contests/lou5/challenges 以下代码是题目的答案 <?php head ...
- 【python】Leetcode每日一题-设计停车系统
[python]Leetcode每日一题-设计停车系统 [题目描述] 请你给一个停车场设计一个停车系统.停车场总共有三种不同大小的车位:大,中和小,每种尺寸分别有固定数目的车位. 请你实现 Parki ...
- Google Code Jam 第一题
通过的第一题,留做纪念,呵呵,非常简单,Africa 2010, Qualification Round: Store Credit. #include <stdio.h> #includ ...
- 2014年的Google I/O app设计中的材料设计-渣渣的翻译
又是一篇翻译,用了三个多小时.http://android-developers.blogspot.co.id/2014/08/material-design-in-2014-google-io-ap ...
- USACO比赛题泛刷
随时可能弃坑. 因为不知道最近要刷啥所以就决定刷下usaco. 优先级排在学习新算法和打比赛之后. 仅有一句话题解.难一点的可能有代码. 优先级是Gold>Silver.Platinum刷不动. ...
- Google发布移动网站设计原则
Google 刚刚发布了由 Google 与 AnswerLab 联合打造,名为<Principles of Mobile Site Design: Delight Users and Driv ...
- C#LeetCode刷题-设计
设计篇 # 题名 刷题 通过率 难度 146 LRU缓存机制 33.1% 困难 155 最小栈 C#LeetCode刷题之#155-最小栈(Min Stack) 44.9% 简单 173 二叉搜索 ...
- 2018 湖南网络比赛题 HDU - 6286 (容斥)
题意:不说了. 更加偏向于数学不好的小可爱来理解的. 这篇博客更加偏重于容斥的讲解.用最直观的数学方法介绍这个题. 思路: 在a<=x<=b. c<=y<=d 中满足 x*y ...
随机推荐
- Delphi判断进程是否存在(使用CreateToolhelp32Snapshot)
program Project2; uses windows,TLHelp32; function FindProcess(AFileName:string):boolean; var hSnap ...
- Linux下快速静态编译Qt以及Qt动态/静态版本共存
Qt下静态编译Qt,根据我的经验,如果按照Windows下那种直接拿官方sdk安装之后的文件来编译是行不通的,需要直接下载Qt的source包,目前诺基亚的源码叫做qt-everywhere-open ...
- 得到RTP包中的timestamp
NTP------网络时间协议 PTP------精确时间协议 PTS,DTS的关系: http://www.cnblogs.com/qingquan/archive/2011/07/27/21189 ...
- Netbeans 学习
1.NetBeans快捷键: 1.完成代码:ctrl+\ //任何地方按下此组合键,均会提示相应的参考字段: 2.错误提示:alt + enter //顾名思义,当系统报错时,按下此组合可以查看系统提 ...
- 【HDOJ】4544 湫湫系列故事——消灭兔子
贪心,普通贪心两层循环TLE了,然后用优先级队列维护内层. #include <iostream> #include <cstdio> #include <cstring ...
- 用DIV+Css+Jquery 实现的旧版微信飞机大战。
用jquery 实现的旧版微信飞机大战. 以前一直都是做后台和业务逻辑,前端很少去做, 现在个小游戏. 方向键控制方向,Ctrl 键 放炸弹(当然你的有炸弹,哈哈)! 主要都是用div+Css实现的, ...
- 深入理解linux网络技术内幕读书笔记(六)--PCI层与网络接口卡
Table of Contents 1 本章涉及的数据结构 1.1 pci_device_id结构 1.2 pci_dev结构 1.3 pci_driver结构 2 PCI NIC设备驱动程序的注册 ...
- 修改cmd的字体
通常打开的cmd默认的字体比较小,字体只有宋体和新宋体两种,如果要修改,需要通过修改注册表才行. 打开regedit后,找到如下路径HKEY_LOCAL_MACHINE\SOFTWARE\Micros ...
- [深入React] 2.综述
在开始本教程前,请先查看官方示例:https://github.com/facebook/react/archive/master.zip 里的 examples 目录. 学习react是一个循序渐进 ...
- 关于退运美国转基因玉米含有MRI 162转基因成分的质疑
6月30日,新华社刊出文章"我国退运125.2万吨进口美国转基因玉米",读后有感. 文章说:国家质检总局办公厅副主任陆春明30日介绍,截至今年6月16日,全国出入境检验检疫机构共在 ...