Java中的编码挑战:给定字母并返回它们的等级

Java中的编码挑战:给定字母并返回它们的等级,java,eclipse,challenge-response,Java,Eclipse,Challenge Response,嘿,为了练习,我发现了这个编码挑战,我已经做了几天了。我有第一部分,但我似乎不知道如何从我现在的位置继续下去。以下是挑战: Consider a "word" as any sequence of capital letters A-Z (not limited to just "dictionary words"). For any word with at least two different letters, there are other words composed of

嘿,为了练习,我发现了这个编码挑战,我已经做了几天了。我有第一部分,但我似乎不知道如何从我现在的位置继续下去。以下是挑战:

    Consider a "word" as any sequence of capital letters A-Z (not limited to 
just "dictionary words"). For any word with at least two different letters, 
there are other words composed of the same letters but in a different order (for 
instance, STATIONARILY/ANTIROYALIST, which happen to both be dictionary words; 
for our purposes "AAIILNORSTTY" is also a "word" composed of the same letters as
these two).

    We can then assign a number to every word, based on where it falls in an 
alphabetically sorted list of all words made up of the same set of letters. One
 way to do this would be to generate the entire list of words and find the 
desired one, but this would be slow if the word is long.
    Write a program which takes a word as a command line argument and prints to 
standard output its number. Do not use the method above of generating the entire
 list. Your program should be able to accept any word 20 letters or less in 
length (possibly with some letters repeated), and should use no more than 1 GB
 of memory and take no more than 500 milliseconds to run. Any answer we check 
will fit in a 64-bit integer.

Sample words, with their rank:
ABAB = 2 
AAAB = 1 
BAAA = 4 
QUESTION = 24572 
BOOKKEEPER = 10743 
NONINTUITIVENESS = 8222334634

    Your program will be judged on how fast it runs and how clearly the code is 
written. We will be running your program as well as reading the source code, so 
anything you can do to make this process easier would be appreciated.
到目前为止,如果所有字母都不同,我的代码可以返回正确答案。这是我的密码:

import java.util.Arrays;
import java.util.Scanner;
public class AthenaDility {

    public static void main (String[] args) {
        //Finds word that is entered
        Scanner scan = new Scanner (System.in);
        String word = scan.next();
        scan.close();

        //added value
        int value = 1;

        //alphabetical representation
        char[] charm = word.toCharArray();
        char[] alphaCharm = word.toCharArray(); 
        Arrays.sort(alphaCharm);

        //Comparer
        for (int m = 0; m < word.length(); m++) {
            for (int c = 0; c < word.length()-1; c++) {
                System.out.println(charm[m] + " " + alphaCharm[c]);

                //Skips if alphaCharm is a space
                if (alphaCharm[c] == '-') {
                }

                //If the same letter it breaks look and begins next
                else if (charm[m] == alphaCharm[c]) {
                    System.out.println("Deleting: " + alphaCharm[c]);
                    alphaCharm[c] = '-'; //Delete letter for it is used and cannot be used to compare at later points
                    break;
                }

                //if the letter in alphaCharm comes before charm
                else if (charm[m] > alphaCharm[c]){
                    System.out.println("Found!");

                    //factorial calculation
                    int factorial = 1;

                    //takes the length of the word minus the current location and one after for factorial
                    for (int f = word.length() - m - 1; f > 0; f--) {
                        System.out.print(f + " ");
                        factorial *= f;
                    }
                    //end loop
                    //Adding to others
                    System.out.println("\n" + "Factorial: " + factorial);
                    value += factorial;
                }
                else {

                }
            }
        }

        //Result
        System.out.println("end: " + value);
    }

}   
导入java.util.array;
导入java.util.Scanner;
公共阶级无神论{
公共静态void main(字符串[]args){
//查找输入的单词
扫描仪扫描=新扫描仪(System.in);
String word=scan.next();
scan.close();
//附加值
int值=1;
//字母表示法
char[]charm=word.toCharArray();
char[]alphaCharm=word.toCharArray();
数组。排序(alphaCharm);
//比较器
for(int m=0;m字母咒语[c]){
System.out.println(“Found!”);
//阶乘计算
整数阶乘=1;
//取单词的长度减去当前位置,然后取一个作为阶乘
对于(int f=word.length()-m-1;f>0;f--){
系统输出打印(f+“”);
阶乘*=f;
}
//端环
//增加
System.out.println(“\n”+”阶乘:“+阶乘);
值+=阶乘;
}
否则{
}
}
}
//结果
System.out.println(“结束:+值);
}
}   
为了尽可能简单地解释它,它创建了两个字符串:一个是字母顺序的字母,另一个是原始单词。然后,该程序一次比较每个字母,原始单词中字母之前的任何字母都会导致对第一个单词之前可能存在的组合数进行阶乘计算

我需要帮助考虑的部分是,如果输入的字符串有多个相同的字母。我已经花了好几天的时间试图解决这个问题。提前谢谢你


p、 为了测试,代码中有很多System.out.println

为什么用
Python
标记?你想让别人用Python重新编写这段代码吗@Andersson这个标签已经被删除了,因为我在网上找到的很多答案都是Python的,我认为至少有人可以比发布它们的人更好地解释它们,这样我就可以使用“策略”,因为没有更好的词了。请看这段最短的java代码:请看java版本:
public static long rankPerm(String perm){}
在接受的答案中。我已经测试了你们分享的所有单词,并得到了准确的答案。