結果

問題 No.346 チワワ数え上げ問題
ユーザー mizunomi32
提出日時 2016-03-01 09:29:20
言語 Java
(openjdk 23)
結果
AC  
実行時間 217 ms / 2,000 ms
コード長 488 bytes
コンパイル時間 3,720 ms
コンパイル使用メモリ 74,500 KB
実行使用メモリ 55,104 KB
最終ジャッジ日時 2024-09-24 13:00:43
合計ジャッジ時間 8,516 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

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