結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
56,168 KB
testcase_01 AC 118 ms
57,384 KB
testcase_02 AC 105 ms
56,212 KB
testcase_03 AC 117 ms
57,376 KB
testcase_04 AC 116 ms
57,460 KB
testcase_05 AC 99 ms
55,640 KB
testcase_06 AC 106 ms
56,196 KB
testcase_07 AC 116 ms
57,164 KB
testcase_08 AC 106 ms
54,156 KB
testcase_09 AC 116 ms
57,220 KB
testcase_10 AC 196 ms
58,372 KB
testcase_11 AC 185 ms
57,708 KB
testcase_12 AC 195 ms
58,264 KB
testcase_13 AC 185 ms
57,696 KB
testcase_14 AC 122 ms
56,540 KB
testcase_15 AC 204 ms
58,420 KB
testcase_16 AC 205 ms
58,236 KB
testcase_17 AC 201 ms
58,276 KB
testcase_18 AC 191 ms
56,184 KB
testcase_19 AC 198 ms
58,308 KB
testcase_20 AC 198 ms
58,280 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 117 ms
57,428 KB
testcase_24 AC 119 ms
57,320 KB
testcase_25 AC 122 ms
57,424 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();
            int 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