[2020年1月3日]学習アルゴリズムの得点記録--11

スコアリングアルゴリズム-11


「ワット」と二人のためのゲームと王張の得点を表す「Z」の文字列を、のみを入力してください含まれています。
例えば"W、W、W、 Z、Z、Z" 王は3ポイント張後、3ポイントを務め表します。
スコアリング規則を既存のとして次の
ラウンドの11点は、第一次のラウンドへの両側の勝利後、勝利を得ました。
出力に各ラウンドのスコアと当事者の現在のラウンドのスコアが必要です。
注: 入力文字列が完全にゲームの終了を表さない、進行中のゲームが存在してもよいです。


public class ScoreElevenAndTwentyOne
{
    public String findEleven(String input){
        char[] rawList = input.toCharArray();
        String result = "";
        int round = 1;
        int scoreA = 0;
        int scoreB = 0;
        for(int i = 0; i < rawList.length; i++){
            if(scoreA<=11 && scoreB<=11){
                if(rawList[i] == 'w'){
                    scoreA ++;
                }
                if(rawList[i] == 'z'){
                    scoreB ++;
                }
            }
            if(scoreA >11 || scoreB > 11){
                if(scoreA>11){
                    scoreA = 11;
                }
                if(scoreB>11){
                    scoreB = 11;
                }
                result += "For Round" + round + ",the score is: " + "WANG: " + scoreA + " ; ZHANG: " + scoreB + " .";
                if(rawList[i] == 'w'){
                    scoreA = 1;
                    scoreB = 0;
                }
                if(rawList[i] == 'z'){
                    scoreA = 0;
                    scoreB = 1;
                }
                round++;
            }
            if(i == rawList.length-1){
                result += "For Round" + round + ",the score is: " + "WANG: " + scoreA + " ; ZHANG: " + scoreB + " .";
            }
        }
        return result;
    }
}


公開された17元の記事 ウォンの賞賛0 ビュー331

おすすめ

転載: blog.csdn.net/cletitia/article/details/103817774