結果

問題 No.346 チワワ数え上げ問題
ユーザー spacia
提出日時 2016-06-02 16:56:17
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 470 bytes
コンパイル時間 2,775 ms
コンパイル使用メモリ 78,440 KB
実行使用メモリ 42,564 KB
最終ジャッジ日時 2024-10-08 05:32:48
合計ジャッジ時間 7,692 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {

	public static void main (String[] args) {

		Scanner sc = new Scanner(System.in);

		System.out.println(solve(sc.next()));

		sc.close();

	}

	public static long solve (String s) {
		int wcnt = 0;
		long sum = 0;
		int len = s.length();
		for (int i = len - 1; i >= 0; i--) {
			if (s.charAt(i) == 'w') {
				wcnt++;
				continue;
			}
			if (s.charAt(i) == 'c')
				sum += wcnt * (wcnt - 1) / 2;
		}
		return sum;
	}

}
0