24小时热门版块排行榜    

北京石油化工学院2026年研究生招生接收调剂公告
查看: 182  |  回复: 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 ]
回复此楼

» 猜你喜欢

上善若水,厚德载物!
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

jjdg

版主 (知名作家)

优秀版主


余泽成(金币+1,VIP+0):支持参与应助,欢迎常来程序软件版! 10-9 12:36
这是要求编一个java做加密的吧!
USE+USE=SEE好像不符合Every character in the encoding string is different from every other character in the encoding string着一条啊!
努力学习!以正当途径!获得需要的知识!
2楼2009-10-09 11:58:56
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 白欣 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 本科新能源科学与工程,一志愿华理能动285求调剂 +7 AZMK 2026-03-28 11/550 2026-03-28 21:01 by xxxsssccc
[考研] 学硕274求调剂 +8 Li李鱼 2026-03-26 8/400 2026-03-28 16:53 by xuxiang
[考研] 266分,求材料冶金能源化工等调剂 +7 哇呼哼呼哼 2026-03-27 9/450 2026-03-28 12:22 by zllcz
[考研] 085602 307分 求调剂 +7 不知道叫什么! 2026-03-26 7/350 2026-03-28 09:57 by 神马都不懂
[考研] 311求调剂 +3 希望上岸阿小杨 2026-03-23 3/150 2026-03-28 07:57 by 热情沙漠
[考研] 一志愿211院校 344分 东北农业大学生物学学硕,求调剂 +5 丶风雪夜归人丶 2026-03-26 8/400 2026-03-27 19:22 by 丶风雪夜归人丶
[考研] 求调剂 +4 零八# 2026-03-27 4/200 2026-03-27 18:07 by yu221
[考研] 266求调剂 +11 阳阳哇塞 2026-03-27 12/600 2026-03-27 17:56 by yu221
[考研] 305求调剂 +5 哇卢卡库 2026-03-26 5/250 2026-03-27 14:01 by laoshidan
[考研] 求调剂 +3 刘柯@ 2026-03-24 4/200 2026-03-27 11:28 by shangxh
[考研] 一志愿郑州大学,080500学硕,总分317分求调剂 +4 举个栗子oi 2026-03-24 5/250 2026-03-26 23:15 by 不吃魚的貓
[考研] 321求调剂 +6 wasdssaa 2026-03-26 6/300 2026-03-26 20:57 by sanrepian
[考研] 化学调剂一志愿上海交通大学336分-本科上海211 +4 小鱼爱有机 2026-03-25 4/200 2026-03-26 10:19 by aa331100
[考研] 303求调剂 +6 蓝山月 2026-03-25 6/300 2026-03-25 22:47 by 418490947
[考研] 一志愿南航 335分 | 0856材料化工 | GPA 4.07 | 有科研经历 +6 cccchenso 2026-03-23 6/300 2026-03-25 22:25 by 544594351
[考研] 材料与化工304求B区调剂 +3 邱gl 2026-03-25 3/150 2026-03-25 19:03 by Ainin_
[考研] 网络空间安全0839招调剂 +4 w320357296 2026-03-25 6/300 2026-03-25 17:59 by 255671
[考研] 284求调剂 +15 Zhao anqi 2026-03-22 15/750 2026-03-25 12:51 by wht0531
[基金申请] 请教下大家 2026年国家基金申请是双盲审吗? +3 lishucheng1 2026-03-22 5/250 2026-03-24 08:22 by gltch
[考研] 341求调剂(一志愿湖南大学070300) +5 番茄头--- 2026-03-22 6/300 2026-03-23 23:45 by Txy@872106
信息提示
请填处理意见