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 the given 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 GRDI GREG GREH GREI GRFG GRFH GRFI GSDG GSDH GSDI GSEG GSEH GSEI GSFG GSFH GSFI HPDG HPDH HPDI HPEG HPEH HPEI HPFG HPFH HPFI HRDG HRDH HRDI HREG HREH HREI HRFG HRFH HRFI HSDG HSDH HSDI HSEG HSEH HSEI HSFG HSFH HSFI IPDG IPDH IPDI IPEG IPEH IPEI IPFG IPFH IPFI IRDG IRDH IRDI IREG IREH IREI IRFG IRFH IRFI ISDG 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
题意:
有一串数字,用上面的”字母数字对应表“规则来找出所有“dict.txt”中的名字。
思路:
先将dict.txt中全部的名字放在namelist[ i ][ j ]中,然后输入一串数字(这串中的数字由一个个字符组成,不是数),当这个名字长度与这串数字字符串的长度相同时,再一个个进行比较,如果全都满足条件,则输出该字符,如果不符合则判断下一个,如果遍历完全部名字后也找不到一个,则输出NONE。
AC:
/* TASK:namenum LANG:C ID:sum-g1 */ #include<stdio.h> #include<string.h> int translate(char a,char b) //另外写个函数判断是否满足条件 { if((a=='A'||a=='B'||a=='C')&&b=='2') return 1; if((a=='D'||a=='E'||a=='F')&&b=='3') return 1; if((a=='G'||a=='H'||a=='I')&&b=='4') return 1; if((a=='J'||a=='K'||a=='L')&&b=='5') return 1; if((a=='M'||a=='N'||a=='O')&&b=='6') return 1; if((a=='P'||a=='R'||a=='S')&&b=='7') return 1; if((a=='T'||a=='U'||a=='V')&&b=='8') return 1; if((a=='W'||a=='X'||a=='Y')&&b=='9') return 1; return 0; } int main() { FILE *list; FILE *fin =fopen("namenum.in","r"); FILE *fout=fopen("namenum.out","w"); char namelist[5000][15]; int i=0,sum,j,sum1; int temp=0,numlen,namelen; char num[15],num1[15]; list=fopen("dict.txt","r"); //文件中的名字复制过程 while(!feof(list)) //判断文件读取完没有,如果读取完则返回1 {fscanf(list,"%s",namelist[i++]);} sum=i; fscanf(fin,"%s",num); //输入一串字符串数字 numlen=strlen(num); for(i=0;i<sum;i++) //循环名字表 { namelen=strlen(namelist[i]); if(namelen==numlen) //判断字符串大小 { sum1=0; for(j=0;namelist[i][j];j++) //循环这个名字 { if(translate(namelist[i][j],num[j]))sum1++; } if(sum1==namelen) { fprintf(fout,"%s\n",namelist[i]); temp=1; } } } if(!temp) fprintf(fout,"NONE\n"); exit(0); }
总结:
题目很简单,我也不懂自己为什么可以磨这么久才磨出来……一开始把输入的1当成数字1而不是字符‘1’,然后处理文件部分又不怎么会处理,犯的低级错误太多了。题目一下子就懂了,但是懂了不代表你马上就能准确的写出来,防止眼高手低,所以无论是简单还是难,都必须逼自己写一遍。简单的都不会,都不熟悉,都那么粗心的话,那难的就更难做AC了。So,继续努力吧。
相关推荐
USACO答案,采用C++写的,题目是:name that number.
USACO题目Name That Number (namenum)及代码解析
Name That Color - Android Studio Plugin Introduction When I get a new color to set in my Android app, I never know how to call it. I used the website Name That Color for years, and I wanted to have ...
name-that-color "#a9d91d"//=> #a9d91d name is Inch Wormname-that-color "a9d91d"//=> a9d91d name is Inch Wormname-that-color "#eee"//=> #eee name is Galleryname-that-color "rgb(124, 96, 200)"//=> rgb...
withdrawal function that returns a bool value deposit function that returns a bool value a way to get available funds should return a double a way to create an account that returns bool value ...
name-that-color-intellij-plugin,作为android studio/intellij插件的“命名颜色”.zip
A naming context is an object that contains a set of name bindings in which each name is unique. Different names can be bound to an object in the same or different contexts at the same time. There is...
8-1 Students I (10分)Write a program that asks you 10 records of students. Each record consists of a name (w/o space) and scores for three courses (in integer 1 to 5). Output a list as following and ...
oracle service_name参数
操作系统实验模拟生产者消费者问题 PROGRAM NAME: PRODUCER_CONSUMER */ /* This program simulates two processes, producer which */ /* continues to produce message and put it into a buffer */ /* ...
虚拟串口软件以及模拟串口如何连接KEIL 仿真指导文档 1.内含有虚拟串口软件以及破解方法 2.内含有一个指导文档,指导针对STM32F1系列单片机...3.文档包含对于error 30: undefined name of virtual register的解决方法。
每一个测试用例包含 number, name, maths, english, science 5种数据,用StudentTest类读取数据,并用数据构造Student类,最终打印学生信息。 StudentTest类运行效果如下: Student Info: Number:2011211301 ...
:right_arrow: | :left_arrow: 现代哈希识别系统pip3 install name-that-hash && nth :thinking_face: 这是什么? 您是否遇到过像5f4dcc3b5aa765d61d8327deb882cf99这样的哈希,并且想知道这是什么类型的哈希? :...
p04 apple 10 banana 25 carrot 100Echo your data.Your program should read the parameters create threads for the words and have that thread count 1 to N (the number following).You should use the ...
本程序 主要是采用C语言程序来模拟操作系统的进程管理原理,采用了常用的数据结构和算法:结构体、单链表和双链表。 Bug说明: 当没有创建任何进程时,调用block()、end()函数时,会出现内存错误!原因:就绪队列...
资源分类:Python库 所属语言:Python 资源全名:name_that_hash-1.1.5-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
本文比较系统地介绍了Oracle中的9个name,如db_name,global_dbname,db_unique_name,instance_name,SID, service_name等参数。
For this assignment, we will read ... Each non-blank line will contain an integer score followed by one or more blanks, followed by a department name that may contain embedded blanks (Computer Science).
jquery模拟,可以实现id选择器,和name选择器和id name二层组合选择器。实现ajax可以使用post方法请求服务器。有利于学习jquery内部实现原理
/* 输入学生成绩并显示 */ # include struct student { char number[6];... printf("%-6s%-6s", stu[i].number, stu[i].name); for(j=0; j; j++) printf("%-8d", stu[i].score[j]); printf("\n"); } }