java—找到完形填空的解决方案

vwkv1x7d  于 2021-07-11  发布在  Java
关注(0)|答案(1)|浏览(220)

我在尝试自动完成完形填空。输入如下所示:

__a _____n _______t _n _i___ _e_________ __s d__ _____e__ __d _i____ e__ __t___. _s _s_ __n_ ____e __n ______n ___e___, _i_ i_ _i_ ___h____ __________e __b_____ ___d__ s_____, _o __s_ s__ _i__ ___t___ _e________ _r_____. __________n _n_ _a_________ s____ e_____ _______b__ ___d ____n ______e___.
Es in in so aus der die die ein ist Opa sie und und von dass eine eine sind einer Liste schon sowie einige findet Jürgen Rätsel sollen werden ergeben gegeben lustige Wörtern Apotheke blättert gebracht richtige Buchstaben Geschichte vorgegeben Leerzeichen Reihenfolge Satzzeichen Zeitschrift

显然我想找到正确的解决办法。应该是这样的:
opa j公司ürgen bl公司ä这是一个非常有趣的故事ä采尔。。。
但它只是输出:
奥帕,jü布勒冈州奥尔根ättert,null,einer,zeitschrift,aus,der,apotheke,null,findet,null,rätsel,。。。
一个问题是,它只在没有其他可能性的情况下填写单词,但是如果列表中有一个单词出现了两次,它就不知道应该用哪个单词。我不知道如何实现这一点,而且肯定还有另一个问题。
它应该循环遍历每个单词的所有“空格”,并查找具有相同和唯一计数的2个单词。这对于没有字母的“空格”很重要。然后再比较一个单词和一个空格,然后在单词的同一个地方寻找同一个字母。
如果它找到了适合它的东西,它会添加到一个计数器以确保它是唯一可能的,然后将这个词添加到输出字符串中。
“stringresult”是空格,“stringresult2”是单词(输入的第一行和第二行)
如果有人能帮我就好了。代码如下:

for(int i = 0; i<stringResult2.length; i++) {
                used[i]= false;
            }
            for(int reps = 0; reps <(stringResult.length +1) ; reps++){

                for(int i=0; i<charCount2.length; i++) {
                // geht alle WÖRTER durch   
                    int counter = 0;
                    int counter2 = 0;
                    int savej1 = 0;
                    int savej2 = 0;
                    String save4Output = null;

                    for(int j=0; j<charCount.length; j++) {
                        if(Final[j] != null) {
                            continue;
                        }
                        else {
                        //geht alle LÜCKEN durch
                            if (charCount2[i] == charCount[j] && Final[j] == null && used[i] == false){
                                counter ++;
                                savej1 = j;

                            }
                        }

                    }
                    if (counter == 1){
                        Final [savej1] = stringResult2[i];
                        used[i] = true;
                    }
                    else if(counter > 1) {

                        char[] letters =new char[stringResult2[i].length()];
                        letters = stringResult2[i].toCharArray();
                        //einzelne Buchstaben von Wörtern

                        for(int j = 0; j < charCount.length; j++) {
                        // geht alle LÜCKEN durch

                            if(Final[j] != null) {
                                continue;
                            }
                            else {

                                if(charCount2[i] == charCount[j]) {

                                    char[] spaces =new char[stringResult[j].length()];
                                    spaces = stringResult[j].toCharArray();
                                    //einzelne Zeichen von Lücken
                                    //int ja = 0;

                                    for(int l = 0; l < spaces.length; l++) {
                                        if(letters[l] == spaces[l] && used[i] == false) {
                                            System.out.println("Jawollja");
                                            savej2 = j;
                                            save4Output =stringResult2[i];
                                            counter2 ++;
                                            //Final[j] = stringResult2[i];
                                            System.out.println(Arrays.toString(Final));
                                            break;
                                        }

                                    }
                                }
                            }

                        }

                        if(counter2 ==1) {
                            Final[savej2] = save4Output;
                            used[i] = true;
                        }
                        else { continue; }

                                                                                                                        //System.out.println(letters);
                    }

                }
            }

                System.out.println(Arrays.toString(Final));

        } catch (IOException ioe) {
            ioe.printStackTrace();
        }

    }

}
    enter code here
chhqkbe1

chhqkbe11#

我已经找到了解决办法。感谢您几周后重新打开它,当时已经很晚了!
顺便说一句,这是个笑话…;-)

相关问题