結果

問題 No.346 チワワ数え上げ問題
ユーザー jp_ste
提出日時 2016-02-28 20:57:53
言語 Java
(openjdk 23)
結果
AC  
実行時間 222 ms / 2,000 ms
コード長 543 bytes
コンパイル時間 2,457 ms
コンパイル使用メモリ 75,308 KB
実行使用メモリ 55,164 KB
最終ジャッジ日時 2024-09-24 12:08:52
合計ジャッジ時間 8,031 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

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