2 shunfurh shunfurh 于 2017.09.15 12:02 提问

Bulk Mailing

An organization that wishes to make a large mailing can save postage by following U.S. Postal Service rules for a bulk mailing. Letters in zip code order are bundled into packets of 10-15 letters each. Bundles may consist of letters in which all 5 digits of zip code are the same (5-digit bundles), or they may consist of letters in which only the first 3 digits of zip code are the same (3-digit bundles). If there are fewer than 10 letters to make up a bundle of either type, those letters are mailed first class.

Input

You are to write a program to read a data set of 5-digit zip codes, one per line, until end of file. Your program should count the number of 5-digit bundles, 3-digit bundles, and first class letters. You should include as many letters as possible in 5-digit bundles first, then as many as possible in 3-digit bundles, with as few bundles of 10 to 20 letters as possible. For example, if there are 31 letters with the same zip code, they must be combined into exactly three 5-digit bundles.

Not all zip codes in the data set will be valid. A valid zip code consists of exactly 5 digits (0-9), all of which cannot be 0. Non-numeric characters are not allowed. At the end of your output, print the invalid zip codes found. (Duplicates need only be printed once.)

Output

Print a report that lists 5-digit zip code bundles first, with the number of letters and number of bundles for each zip code. Next list all 3-digit zip code bundles with the same two counts, followed by all zip codes that are not bundled and to be sent first class. At the end print totals of letters and bundles, followed by the number of invalid zip codes and a list of these. Single space the report, and print blank lines following the heading, before the total line, and between the three groups of zip codes. For 3-digit bundles, print the zip codes in the form dddxx, where ddd represents the three significant digits and xx represents the last two digits to be omitted.

Sample Input

95864
95864
95864
95867
95920
9j876
95616
95616
95747
95814
95818
95818
8976
95818
95818
95819
95819
00000
95819
95819
95819
95819
95819
95825
95825
95825
95825
95825
95826
95826
95826
95826
95826
95826
95827
8976
95833
95833
95833
95833
95819
95819
95819
95819
95833
95833
95833
95864
95864
95864
123456
95864
95864
95864
95864

Sample Output

ZIP LETTERS BUNDLES

95819 11 1
95864 10 1

958xx 25 2

95616 2 0
95747 1 0
95920 1 0

TOTALS 50 4

INVALID ZIP CODES
9j876
8976
00000
123456

2个回答

caozhy
caozhy   Ds   Rxr 2017.09.16 10:53
已采纳
shen_wei
shen_wei   Ds   Rxr 2017.09.15 15:44
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
第一次用Mailing List
<br />哎呀!<br />为了让lisp写的代码可以给C++调用,找到ECL可以生成动态库和静态库.<br />然后下载,编译,试看.结果不得行,没有调用vc的编译器(它本来是会使用C/C++编译器,把lisp转换成C的),结果不对头.<br />囊个办呢~只好去问看,就用了它的mailing list.<br />结果发完了一看在众多的E文名字邮箱中,就我一个中文名字的邮箱,好显眼.<br />
POJ 1055 BULK MAILING 笔记
给出每封信的邮编。分为5位邮编都相同的类,前3位相同的类。这两类每包由10到15封信组成。分类中少于10封的是一类。
debian下不能发邮件到外网的问题
最近工作关系有用到debian版本的linux,安装后配合PHP发信,居然不成功,超郁闷,之前一直用freebsd 安装上可直接用php发邮件,最后查一下原因发现debian下面默认的邮件系统非sendmail 而是exim4,经过一番的努力找到下面的贴子把问题解决了,希望此贴对遇到如我一样的朋友有些帮助,另外要感谢FUNction朋友的在此过程中的帮助,他对exim4+php有些体验,附在文章最
向Maillist投送邮件的注意事项
很多开源项目的问题解答,都使用邮件列表系统,比如 GNU mail man。 这种系统通过向特定邮件地址发送邮件,即可把问题广播给所有感兴趣的订阅者(已经事先subscribe该专题的邮件收件人 )。但是为了防止垃圾邮件,很多系统除了要求邮件格式为“plain text” 外,都还有较强的检测策略。如果不注意,就无法成功发送邮件。这些天,为了反馈这个C++ shared_ptr管理二维数组的编
在shell中发送邮件的相关问题
环境:ubuntu10.04 首先要安装软件包mailutils :apt-get install heirloom-mailx 1、先通过通过mail给系统内的其他用户发送邮件 mail  -s “这是邮件的主题”   user1 ********* *********** . (另启一行输入一个“.” 再按回车结束内容的输入) su  -  user1
在shell中发邮件
周海汉 /文2009.12.18 一个服务程序,需要知道它的运行情况,将探测报告定期发送给运维人员,对错误要立即告警。在任何一台能上网的linux机器,需要能部署发送邮件。 写脚本探测程序和系统运行情况基本完成,现在需要告警和定期发送邮件。采用exim4程序 sudo apt-get install mailutils 安装完毕,输入命令 mail xxx@zh
订阅Linux的邮件列表
学习Linux内核可以订阅Linux的邮件列表,订阅的方法如下: 1、登录网站:http://vger.kernel.org/vger-lists.html 2、选择用户感兴趣的Linux内核模块,例如Linux-kernel 3、登录用户自己的邮箱 4、写邮件,发送地址为:majordomo@vger.kernel.org 5、邮件内容为:subscribe lin
实用英文地址书写格式
<br />英文地址书写格式<br />***室/房 Room ***<br />***单元Unit ***<br />***村 *** Vallage<br />***号楼/栋 *** Building<br />***号 No.***<br />***公司 *** Com.或*** Crop或***LTD.CO<br />***号宿舍 *** Dormitory<br />***厂 *** Factory<br />***楼/层 ***/F<br />***酒楼/酒店 *** Hotel<br />**
[c语言]EmailAddresses(for hw)
You’ve gathered some e-mail addresses from a variety of sources, and you want to send out a mass mailing to all of the addresses. However, you don’t want to send out duplicate messages. You need to wri
sal,ename BULK COLLECT INTO
sal,ename BULK COLLECT INTO sal,ename BULK COLLECT INTO sal,ename BULK COLLECT INTO vsal,ename BULK COLLECT INTO sal,ename BULK COLLECT INTO sal,ename BULK COLLECT INTO sal,ename BULK COLLECT INTO