結果

問題 No.346 チワワ数え上げ問題
ユーザー hhgfhn1hhgfhn1
提出日時 2018-10-23 00:36:57
言語 Java
(openjdk 23)
結果
AC  
実行時間 644 ms / 2,000 ms
コード長 501 bytes
コンパイル時間 3,243 ms
コンパイル使用メモリ 74,724 KB
実行使用メモリ 54,600 KB
最終ジャッジ日時 2024-11-19 04:00:14
合計ジャッジ時間 8,706 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		String s=scanner.next();
		int cnt=0;
		long ans=0;
		for(int i=s.length()-1;i>=0;i--) {
			char c=s.charAt(i);
			if(c=='w') {
				cnt++;
			}else if(c=='c'){
				ans+=calc(cnt-1);
			}
		}
		System.out.println(ans);
	}

	private static long calc(int cnt) {
		long res=0;
		for(int i=cnt;i>0;i--) {
			res+=i;
		}
		return res;
	}
}
0