結果

問題 No.346 チワワ数え上げ問題
ユーザー matsuyoshi30matsuyoshi30
提出日時 2018-09-11 23:07:51
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 412 bytes
コンパイル時間 3,898 ms
コンパイル使用メモリ 71,508 KB
実行使用メモリ 56,952 KB
最終ジャッジ日時 2023-09-06 15:12:12
合計ジャッジ時間 7,317 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
56,176 KB
testcase_01 AC 120 ms
55,732 KB
testcase_02 AC 115 ms
55,824 KB
testcase_03 AC 114 ms
55,996 KB
testcase_04 AC 118 ms
55,828 KB
testcase_05 AC 116 ms
55,716 KB
testcase_06 AC 118 ms
56,172 KB
testcase_07 AC 115 ms
55,900 KB
testcase_08 AC 119 ms
55,900 KB
testcase_09 AC 115 ms
56,236 KB
testcase_10 WA -
testcase_11 AC 166 ms
56,592 KB
testcase_12 WA -
testcase_13 AC 176 ms
56,560 KB
testcase_14 AC 125 ms
55,972 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 189 ms
56,592 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 113 ms
56,112 KB
testcase_24 AC 114 ms
55,784 KB
testcase_25 AC 116 ms
55,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();

        int l = s.length();
        int ans = 0;
        int wc = 0;

        for(int i=l-1; i>=0; i--) {
            if(s.charAt(i) == 'w') wc++;
            if(s.charAt(i) == 'c') ans += wc * (wc-1) / 2;
        }

        System.out.println(ans);
    }
}
0