| 查看: 165 | 回复: 1 | |||
| 当前主题已经存档。 | |||
| 【有奖交流】积极回复本帖子,参与交流,就有机会分得作者 白欣 的 20 个金币 | |||
[交流]
【求助】请高手帮忙解题!
|
|||
|
Cryptarithmetic Cryptarithmetic involves arithmetic on numbers where the digits have been encoded as letters. A cryptarithmetic puzzle usually requires you to work out which digit each letter stands for. For example, if you are told that someone has to use some eye medication twice in order to see, so: USE + USE = SEE you have to work out that E stands for 0, S stands for 5, and U stands for 2, so the unencoded expression is: 250 + 250 = 500 In this assignment the task is simplified to repeatedly working out the result of a cryptarithmetic operation given the encoding scheme, e.g. given what the letters stand for and the following expression: USE + USE your program will have to unencode the encoded numbers into ints, do the arithmetic operation and encode the result, so as to work out that: USE + USE = SEE (Hint: Make sure that you understand the String methods, such as indexOf, before you try to work out how to unencode and encode.) The arithmetic is to be done as integer arithmetic, e.g. 3/2 = 1, and all numbers will be such that the actual arithmetic can be done with ints, and will never involve negative numbers. (You can look up more about cryptarithmetic on e.g. Wikipedia, but you may not use any code that you find there, or elsewhere, which relates to cryptarithmetic — not even as a starting point for your own code.) User Interaction The program must first explain to the user how to use it. It must then repeatedly ask the user what they want to do next. Whenever the user enters "Cryptarithmetic" (without quotes) after being asked what to do next, the program will: Prompt the user to enter a one operation cryptarithmetic expression, starting with the encoding. Read 4 Strings, using Scanner's next() method. The strings represent: The encoding scheme, identifying the letters for digits in order from the letter for 0, e.g. "EAUBCSDFGH" (without quotes) would show that 0 is represented by E, 1 is represented by A, 2 is represented by U, ..., 5 is represented by S, ... 9 is represented by H. The first operand, e.g. "USE" (without quotes). The operator, e.g. "+" (without quotes). The second operand, e.g. "USE" (without quotes). If it was a valid cryptarithmetic encoding and expression, output (with appropriate spacing) the cryptarithmetic expression with = and result for what the user entered, e.g.: USE + USE = SEE Otherwise output an error message. The encoding and expression are to be considered valid, if (and only if) all the following are true: The encoding string contains exactly 10 characters. Every character in the encoding string is an upper case letter. Every character in the encoding string is different from every other character in the encoding string. Every character in the first operand is in the encoding string. The operator string contains exactly one character. The character in the operator string is one of the standard Java arithmetic operators: +, -, *, /, %. Every character in the second operand is in the encoding string. If the user enters anything other than "Cryptarithmetic" (without quotes) after being asked what to do next, the program must stop, returning from the main(). This link shows an example of user interaction of the appropriate form. (The user has indented each thing they enter so that you can see which lines they enter and which the computer has produced. This has only been done for ease of reading. Your program will be tested without such indenting.) You must make up your own (appropriate) messages to the user, but your program must accept input of exactly the form specified, and display the cryptarithmetic results as specified. (We must be able to test your program automatically by feeding it input of the specified form and easily comparing the output produced with the expected output 主要就是说E A U B C S D F G H 0 1 2 3 4 5 6 7 8 9 这些对应,然后进行一个循环运算的编程,有高手有答案的,请帮忙,万分感谢!!! [ Last edited by 白欣 on 2009-9-10 at 23:01 ] |
» 猜你喜欢
假如你的研究生提出不合理要求
已经有4人回复
论文终于录用啦!满足毕业条件了
已经有27人回复
所感
已经有3人回复
要不要辞职读博?
已经有7人回复
不自信的我
已经有11人回复
北核录用
已经有3人回复
实验室接单子
已经有3人回复
磺酰氟产物,毕不了业了!
已经有8人回复
求助:我三月中下旬出站,青基依托单位怎么办?
已经有10人回复
26申博(荧光探针方向,有机合成)
已经有4人回复

jjdg
版主 (知名作家)
- 程序强帖: 9
- 应助: 223 (大学生)
- 贵宾: 3.926
- 金币: 51003.4
- 红花: 238
- 帖子: 7227
- 在线: 474.2小时
- 虫号: 27000
- 注册: 2003-10-21
- 专业: 药物代谢与药物动力学
- 管辖: 程序语言

2楼2009-10-09 11:58:56












回复此楼