USACO section 1.2 Name That Number
来源:互联网 发布:淘宝商品老是被删除 编辑:程序博客网 时间:2024/05/16 10:22
Among the large Wisconsin cattle ranchers, it is customary to brand cows with serial numbers to please the Accounting Department. The cow hands don't appreciate the advantage of this filing system, though, and wish to call the members of their herd by a pleasing name rather than saying, "C'mon, #4734, get along."
Help the poor cowhands out by writing a program that will translate the brand serial number of a cow into possible names uniquely associated with that serial number. Since the cow hands all have cellular saddle phones these days, use the standard Touch-Tone(R) telephone keypad mapping to get from numbers to letters (except for "Q" and "Z"):
2: A,B,C 5: J,K,L 8: T,U,V 3: D,E,F 6: M,N,O 9: W,X,Y 4: G,H,I 7: P,R,S
Acceptable names for cattle are provided to you in a file named "dict.txt", which contains a list of fewer than 5,000 acceptable cattle names (all letters capitalized). Take a cow's brand number and report which of all the possible words to which that number maps are in thegiven dictionary which is supplied as dict.txt in the grading environment (and is sorted into ascending order).
For instance, the brand number 4734 produces all the following names:
GPDG GPDH GPDI GPEG GPEH GPEI GPFG GPFH GPFI GRDG GRDH GRDIGREG GREH GREI GRFG GRFH GRFI GSDG GSDH GSDI GSEG GSEH GSEIGSFG GSFH GSFI HPDG HPDH HPDI HPEG HPEH HPEI HPFG HPFH HPFIHRDG HRDH HRDI HREG HREH HREI HRFG HRFH HRFI HSDG HSDH HSDIHSEG HSEH HSEI HSFG HSFH HSFI IPDG IPDH IPDI IPEG IPEH IPEIIPFG IPFH IPFI IRDG IRDH IRDI IREG IREH IREI IRFG IRFH IRFIISDG ISDH ISDI ISEG ISEH ISEI ISFG ISFH ISFI
As it happens, the only one of these 81 names that is in the list of valid names is "GREG".
Write a program that is given the brand number of a cow and prints all the valid names that can be generated from that brand number or ``NONE'' if there are no valid names. Serial numbers can be as many as a dozen digits long.
PROGRAM NAME: namenum
INPUT FORMAT
A single line with a number from 1 through 12 digits in length.SAMPLE INPUT (file namenum.in)
4734
OUTPUT FORMAT
A list of valid names that can be generated from the input, one per line, in ascending alphabetical order.SAMPLE OUTPUT (file namenum.out)
GREG
在威斯康辛州牛大农场经营者之中,都习惯于请会计部门用连续数字给母牛打上烙印。
但是,母牛用手机时并没感到这个系统的便利,它们更喜欢用它们喜欢的名字来呼叫它们的同伴,而不是用像这个的语句"C'mon, #4734, get along."。
请写一个程序来帮助可怜的牧牛工将一只母牛的烙印编号翻译成一个可能的名字。
因为母牛们现在都有手机了,使用那标准的按键的排布来把收到从数目翻译到文字:( 除了为之外 "Q" 和 "Z")
2: A,B,C 5: J,K,L 8: T,U,V3: D,E,F 6: M,N,O 9: W,X,Y4: G,H,I 7: P,R,S可接受的名字都被放在这样一个叫作"dict.txt" 的文件中,它包含一连串的少于 5,000个可接受的牛名字。 (所有的名字都是大写的)收到母牛的编号返回那些能从编号翻译出来并且在字典中的名字。举例来说,编号 4734 能产生的下列各项名字:
GPDG GPDH GPDI GPEG GPEH GPEI GPFG GPFH GPFI GRDG GRDH GRDIGREG GREH GREI GRFG GRFH GRFI GSDG GSDH GSDI GSEG GSEH GSEIGSFG GSFH GSFI HPDG HPDH HPDI HPEG HPEH HPEI HPFG HPFH HPFIHRDG HRDH HRDI HREG HREH HREI HRFG HRFH HRFI HSDG HSDH HSDIHSEG HSEH HSEI HSFG HSFH HSFI IPDG IPDH IPDI IPEG IPEH IPEIIPFG IPFH IPFI IRDG IRDH IRDI IREG IREH IREI IRFG IRFH IRFIISDG ISDH ISDI ISEG ISEH ISEI ISFG ISFH ISFI碰巧,81个中只有一个"GREG"是有效的(在字典中)。Challenge One写一个程序来对给出的编号打印出所有的有效名字,如果没有则输出"NONE'' 。编号可能有12位数字。
PROGRAM NAME: namenum
INPUT FORMAT
单独的一行包含一个编号(长度可能从1到12)。
SAMPLE INPUT (file namenum.in)
4734
OUTPUT FORMAT
以字典顺序输出一个有效名字的不负列表,一行一个名字。
SAMPLE OUTPUT (file namenum.out)
GREG
#include <stdio.h> #include <string.h> #include <math.h> char Dict[5000][20];//如果想要省空间的话这个数组完全可以不要 char numsplit[13]; int num[13]; int a[100]; int DictSize,len,numlen; int isEqual(int *a, int lena, char *b, int lenb); int main() { int i=0,j,number=0,n=0; int flag=1; freopen("namenum.out","w",stdout); //对字符初始化 将字母和手机上的键盘对应 a[65] = 2; a[66] = 2; a[67] = 2; a[68] = 3; a[69] = 3; a[70] = 3; a[71] = 4; a[72] = 4; a[73] = 4; a[74] = 5; a[75] = 5; a[76] = 5; a[77] = 6; a[78] = 6; a[79] = 6; a[80] = 7; a[82] = 7; a[83] = 7; a[84] = 8; a[85] = 8; a[86] = 8; a[87] = 9; a[88] = 9; a[89] = 9; freopen("namenum.in","r",stdin); scanf("%s",numsplit); numlen=strlen(numsplit); for(i=0;i<numlen;i++) { numsplit[i]-='0';//将字符读入的数字都处理一下,后面好比较 } i=0; freopen("dict.txt","r",stdin); //这里把读入和处理放到一起了 这样就减少了对字典的操作次数 while(scanf("%s",&Dict[i])!=EOF) {//直到文件末尾 getchar(); len = strlen(Dict[i]); n=0; for(j=0;j<len;j++) { num[j]=a[Dict[i][j]];//把字典里的名字翻译成数字 } if(isEqual(num,len,numsplit,numlen)) {//比较 flag=0; printf("%s\n",Dict[i]); } i++; } if(flag)printf("NONE\n"); return 0; }//比较两个数的大小 //是专门为这个写的所以第二个数组是字符数组 int isEqual(int *a, int lena, char *b, int lenb) { int i; if(lena!=lenb)return 0; for(i=0;i<lena;i++) { if(a[i]!=b[i])return 0; } return 1; }
- USACO section 1.2 Name That Number
- USACO Section 1.2 Name That Number
- USACO section 1.2.3 Name That Number
- USACO Section 1.2.4 Name That Number
- USACO Section 1.2 Name That Number
- USACO Section 1.2.3 Name That Number
- USACO Section 1.2 Name That Number
- USACO Section 1.2 Name That Number
- USACO Section 1.2 Name That Number
- USACO-Section 1.2 Name That Number[...]
- USACO Section 1.2 Name That Number(全排列)
- Section 1.2 Name That Number
- Section 1.2 Name That Number
- USACO 1.2-Name That Number
- USACO 1.2 Name That Number
- USACO 1.2 Name That Number
- USACO--1.2Name That Number
- USACO 1.2 Name That Number
- 对于一个频繁使用的短小函数,在C语言中应用什么实现,在C++中应用什么实现?
- POJ1584
- MSDE 安装参数说明
- c/c++程序的内存分配
- 转载:Sensor传感器源码的阅读与应用开发简单实例
- USACO section 1.2 Name That Number
- pb的多态思想
- Android对数据库表的一个约定:每张表都应该至少有_id这列
- sprintf详解
- 以程序的方式操纵NTFS的文件权限
- .NET打包安装MSDE以及安装和卸载
- Poj2266/Poj2270(四元树) .
- 斜堆(Skew Heap)
- tmux 多窗口管理器