(于敏、王大珩(héng)、王希季、朱光亚、孙家栋、任新民、吴自良、陈芳允、陈能宽、杨嘉墀(chí)、周光召、钱学森、屠守锷、黄纬禄、程开甲、彭桓武,王淦(gàn)昌、邓稼先、赵九章、姚桐斌、钱骥、钱三强、郭永怀)。 设计实现一个代号对应名字的猜字系统,需要实现当猜测失败后,随机出相应的提醒,提醒包括首字的笔画,总笔画,首字拼音字母等其中之一。请使用java编写
时间: 2023-09-14 18:06:15 浏览: 73
基于选择性集成神经网络的电路板故障智能诊断 (2014年)
好的,这是一个简单的 Java 实现,您可以参考一下:
```java
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.Scanner;
public class GuessNameGame {
static Map<String, String> nameDict = new HashMap<>();
static Map<String, Map<String, String>> hints = new HashMap<>();
static {
nameDict.put("001", "于敏");
nameDict.put("002", "王大珩(héng)");
nameDict.put("003", "王希季");
nameDict.put("004", "朱光亚");
nameDict.put("005", "孙家栋");
nameDict.put("006", "任新民");
nameDict.put("007", "吴自良");
nameDict.put("008", "陈芳允");
nameDict.put("009", "陈能宽");
nameDict.put("010", "杨嘉墀(chí)");
nameDict.put("011", "周光召");
nameDict.put("012", "钱学森");
nameDict.put("013", "屠守锷");
nameDict.put("014", "黄纬禄");
nameDict.put("015", "程开甲");
nameDict.put("016", "彭桓武");
nameDict.put("017", "王淦(gàn)昌");
nameDict.put("018", "邓稼先");
nameDict.put("019", "赵九章");
nameDict.put("020", "姚桐斌");
nameDict.put("021", "钱骥");
nameDict.put("022", "钱三强");
nameDict.put("023", "郭永怀");
Map<String, String> strokeNumHints = new HashMap<>();
strokeNumHints.put("001", "9");
strokeNumHints.put("002", "16");
strokeNumHints.put("003", "12");
strokeNumHints.put("004", "14");
strokeNumHints.put("005", "11");
strokeNumHints.put("006", "15");
strokeNumHints.put("007", "10");
strokeNumHints.put("008", "12");
strokeNumHints.put("009", "11");
strokeNumHints.put("010", "13");
strokeNumHints.put("011", "13");
strokeNumHints.put("012", "16");
strokeNumHints.put("013", "13");
strokeNumHints.put("014", "17");
strokeNumHints.put("015", "11");
strokeNumHints.put("016", "14");
strokeNumHints.put("017", "11");
strokeNumHints.put("018", "13");
strokeNumHints.put("019", "18");
strokeNumHints.put("020", "16");
strokeNumHints.put("021", "10");
strokeNumHints.put("022", "13");
strokeNumHints.put("023", "13");
hints.put("stroke_num", strokeNumHints);
Map<String, String> pinyinHints = new HashMap<>();
pinyinHints.put("001", "Y");
pinyinHints.put("002", "W");
pinyinHints.put("003", "W");
pinyinHints.put("004", "Z");
pinyinHints.put("005", "S");
pinyinHints.put("006", "R");
pinyinHints.put("007", "W");
pinyinHints.put("008", "C");
pinyinHints.put("009", "C");
pinyinHints.put("010", "Y");
pinyinHints.put("011", "Z");
pinyinHints.put("012", "Q");
pinyinHints.put("013", "T");
pinyinHints.put("014", "H");
pinyinHints.put("015", "C");
pinyinHints.put("016", "P");
pinyinHints.put("017", "G");
pinyinHints.put("018", "D");
pinyinHints.put("019", "Z");
pinyinHints.put("020", "Y");
pinyinHints.put("021", "Q");
pinyinHints.put("022", "Q");
pinyinHints.put("023", "G");
hints.put("pinyin", pinyinHints);
}
public static void main(String[] args) {
System.out.println("欢迎来玩猜字游戏!");
System.out.printf("一共有%d个名字,代号从001到023。\n", nameDict.size());
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.print("请输入代号进行猜测:");
String code = scanner.nextLine();
if (nameDict.containsKey(code)) {
System.out.printf("恭喜你猜对了!这个代号对应的名字是:%s\n", nameDict.get(code));
break;
} else {
String hintType = randomChoice(new String[]{"stroke_num", "pinyin"});
String hint = hints.get(hintType).get(code);
System.out.printf("猜错了,这个名字的%s是:%s\n", hintType, hint);
}
}
}
public static <T> T randomChoice(T[] arr) {
return arr[new Random().nextInt(arr.length)];
}
}
```
希望这个 Java 实现对您有所帮助!
阅读全文