拼字游戏之类的 [英] Scrabble Sort Of

查看:113
本文介绍了拼字游戏之类的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能让一个code,使得它如此,在字母表中的每个字母被分配到一个拼字游戏分数?例如= 1分,B = 3点,C = 3分。然后,如果我有字符串abc字符串的值是7分。这个想法我至今是这两个数组:

 私人INT []积分= {1,3,3,2,1,4,2,4,1,8,5,1,3,1,1,3 ,10,1,1,1,1,4,4,8,4,10};
私人信件的String [] = {\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\",\"k\",\"l\",\"m\",\"n\",\"o\",\"p\",\"q\",\"r\",\"s\",\"t\",\"u\",\"v\",\"w\",\"x\",\"y\",\"z\"};


解决方案

您可以使用的HashMap 。在的get()部分将返回3. 字符串也可以更改为char与字符

 的HashMap<字符串,整数>地图=新的HashMap<字符串,整数>();
    map.put(一,1);
    map.put(B,3);    map.get(B);

How can I make a code that makes it so that each letter in the alphabet is assigned to a Scrabble Score? For example a= 1 point, b= 3 point, c= 3 points. Then if I have String "abc" the value of the String would be 7 points. The idea I have so far is these two arrays:

private int[] Points= {1,3,3,2,1,4,2,4,1,8,5,1,3,1,1,3,10,1,1,1,1,4,4,8,4,10};
private String Letters[] = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};

解决方案

You can use a HashMap. The get() part will return 3. The String can also be changed to a char with Character.

HashMap<String, Integer> map=new HashMap<String, Integer>();
    map.put("a", 1);
    map.put("b", 3);

    map.get("b");

这篇关于拼字游戏之类的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆