結果

問題 No.346 チワワ数え上げ問題
ユーザー mizunomi32mizunomi32
提出日時 2016-03-01 09:29:20
言語 Java21
(openjdk 21)
結果
AC  
実行時間 210 ms / 2,000 ms
コード長 488 bytes
コンパイル時間 4,493 ms
コンパイル使用メモリ 77,424 KB
実行使用メモリ 58,428 KB
最終ジャッジ日時 2023-10-24 19:17:37
合計ジャッジ時間 8,539 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
57,400 KB
testcase_01 AC 122 ms
57,080 KB
testcase_02 AC 124 ms
57,436 KB
testcase_03 AC 124 ms
57,416 KB
testcase_04 AC 126 ms
57,200 KB
testcase_05 AC 111 ms
56,112 KB
testcase_06 AC 128 ms
57,480 KB
testcase_07 AC 113 ms
56,068 KB
testcase_08 AC 124 ms
57,408 KB
testcase_09 AC 125 ms
57,284 KB
testcase_10 AC 210 ms
57,988 KB
testcase_11 AC 188 ms
57,820 KB
testcase_12 AC 210 ms
57,928 KB
testcase_13 AC 185 ms
57,640 KB
testcase_14 AC 134 ms
57,112 KB
testcase_15 AC 207 ms
58,152 KB
testcase_16 AC 206 ms
58,428 KB
testcase_17 AC 207 ms
58,136 KB
testcase_18 AC 198 ms
58,324 KB
testcase_19 AC 194 ms
58,256 KB
testcase_20 AC 198 ms
58,192 KB
testcase_21 AC 195 ms
58,220 KB
testcase_22 AC 203 ms
58,192 KB
testcase_23 AC 119 ms
56,992 KB
testcase_24 AC 123 ms
57,444 KB
testcase_25 AC 121 ms
57,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class main {
    public static void main (String[] args){
        Scanner sc = new Scanner(System.in);
        String S=sc.nextLine();
        int slen= S.length();

        long count =0;
        long ans=0;
        for(int i =slen-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