結果

問題 No.346 チワワ数え上げ問題
ユーザー jp_stejp_ste
提出日時 2016-02-28 20:57:53
言語 Java21
(openjdk 21)
結果
AC  
実行時間 212 ms / 2,000 ms
コード長 543 bytes
コンパイル時間 2,281 ms
コンパイル使用メモリ 74,268 KB
実行使用メモリ 58,588 KB
最終ジャッジ日時 2023-10-24 18:47:39
合計ジャッジ時間 6,999 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
57,548 KB
testcase_01 AC 115 ms
56,220 KB
testcase_02 AC 108 ms
56,212 KB
testcase_03 AC 118 ms
57,224 KB
testcase_04 AC 112 ms
56,320 KB
testcase_05 AC 123 ms
57,188 KB
testcase_06 AC 122 ms
57,628 KB
testcase_07 AC 118 ms
57,512 KB
testcase_08 AC 119 ms
57,176 KB
testcase_09 AC 119 ms
57,184 KB
testcase_10 AC 188 ms
58,252 KB
testcase_11 AC 183 ms
57,904 KB
testcase_12 AC 202 ms
58,288 KB
testcase_13 AC 181 ms
57,864 KB
testcase_14 AC 128 ms
57,208 KB
testcase_15 AC 198 ms
58,064 KB
testcase_16 AC 204 ms
58,360 KB
testcase_17 AC 209 ms
58,588 KB
testcase_18 AC 207 ms
56,440 KB
testcase_19 AC 212 ms
58,236 KB
testcase_20 AC 208 ms
58,420 KB
testcase_21 AC 209 ms
58,252 KB
testcase_22 AC 205 ms
58,172 KB
testcase_23 AC 121 ms
57,584 KB
testcase_24 AC 121 ms
57,456 KB
testcase_25 AC 121 ms
57,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner scan = new Scanner(System.in)) {
            String S = scan.nextLine();
            long count = 0;
            long ans = 0;
            for(int i=S.length()-1; i>=0; i--) {
                if(S.charAt(i) == 'w') {
                    count++;
                } else if(S.charAt(i) == 'c') {
                    ans += count * (count-1) / 2;
                }
            }
            System.out.println(ans);
        }
    }
}
0