早教吧 育儿知识 作业答案 考试题库 百科 知识分享

英语翻译L-I-N-G-O:LINGOAsanexample,theproductionstaffchoosesthesecretword:"HELLO".Thecontestantistoldthefirstletterofthewordis"H".Thecontestantthenguesseswhatthewordcouldbe,knowingitbeginswiththeletter"H".Let'ssa

题目详情
英语翻译
L-I-N-G-O:LINGO
As an example,the production staff chooses the secret word:"HELLO".The contestant is told the first letter of the word is "H".The contestant then guesses what the word could be,knowing it begins with the letter "H".Let's say the contestant guesses the word:"HOLES".The game show computer would report that the "H" and "L" are in the secret word and in the correct position.In addition,the "O" and "E" are in the secret word,but in the incorrect position,and the "S" is not in the secret word.This is conveyed to the contestant by a single line report:
HoLe.
The upper case letters ("H" and "L") indicate correct letter and position.The lower case letters ("o" and "e") indicate correct letter,wrong position.The period (".") indicates a wrong letter (not in the secret word).
You will write a program that evaluates the contestant guesses,and prints out the single line report for each guess.If the contestant guesses the secret word exactly,then the five capital letters of the secret word will be displayed in the report.
Input
The input data file consists of datasets for one or more games.A blank line marks the beginning of the next dataset (game).The line after the blank line contains the secret word.The remaining lines in the dataset represent the contestant's guesses; there may be too few or too many guesses than are necessary to guess the secret word.The secret word will contain exactly five upper case letters.The contestant抯 guesses,however,have to be checked for validity:valid guesses consist of exactly five upper case letters.Input is terminated by a dataset with the secret word:"LINGO" (that is,game play is stopped at that point,the program terminates,and no further guessing occurs).
Output
Each game's output should be preceded by a single blank line (except for the terminating case).The first single line status report should be printed,which consists of the first letter of the secret word,followed by four periods.For each guess,print the single line status report for that guess.For an invalid guess,repeat the previous single line status report.If the guess exactly matches the secret word,that game ends and you should move on to the next one.The contestant may guess a maximum of six times; after the sixth guess,if the contestant did not guess the secret word,or you run out of guesses (the contestant gives up) print out the secret word in lower case letters and move on to the next game.
▼优质解答
答案和解析
作为一个例子,生产人员选择的秘密词:该选手被告知这个词的第一个字母为“H”.该参赛者然后会猜测可能是这个词,知道它与字母“H”开头.让我们猜测说,选手的词:“洞”.游戏节目的计算机会报告中的“H”和“L”是在秘密的文字和在正确的位置.
此外,“O”类和“E”是在秘密的词,但不正确的位置,和“S”是不是在秘密字.这是传达给选手由单一行报告:
洞.
在大写字母(为“H”和“L”)显示正确的字母和立场.小写字母(“0”和“e”)显示正确的字母,错位置.这一时期(".")表示一个错误的信(不是秘密字).
你将写一个程序,用于评估选手猜测,并指出每个guess.If参赛者猜测词准确的秘密,那么5个秘密字大写字母打印单线报告将在报告中显示.
输入
输入数据文件的数据集包含一个或多个游戏.阿空行标志着下一个数据集(游戏)的开始.后的空白行行包含单词的秘密.在DataSet其余线代表选手的猜测,有可能太少或太多猜测比必要的猜测单词的秘密.
秘密字将包含在五个大写字母.该参赛者抯猜测,不过,要检查的有效性:有效的猜测恰好5大写字母组成.输入终止与秘密词集:“LINGO的”(即游戏是在该点停止,程序终止,并没有出现进一步的猜测).
输出
每场比赛的输出之前应该由一个空行(除终止的情况下).第一单线情况报告应印,其中包括对秘密单词的首字母,然后由四个时期.对于每一个猜测,打印该猜测单行情况的报告.对于无效的猜测,重复以前的单一行情况的报告.
如果猜测完全匹配的秘密字,那场比赛结束,你应该进入下一个one.The选手可能会猜6次为限;后的第六猜测,如果参赛者没有猜字的秘密,或者运行出于猜测(该选手放弃)打印出小写字母,并转移到下一场比赛的秘密字.