結果

問題 No.346 チワワ数え上げ問題
ユーザー hhgfhn1
提出日時 2018-10-23 00:35:44
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 498 bytes
コンパイル時間 2,518 ms
コンパイル使用メモリ 74,396 KB
実行使用メモリ 54,728 KB
最終ジャッジ日時 2024-11-19 03:59:38
合計ジャッジ時間 9,384 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14 WA * 9
権限があれば一括ダウンロードができます

ソースコード

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;
		int 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 int calc(int cnt) {
		int res=0;
		for(int i=cnt;i>0;i--) {
			res+=i;
		}
		return res;
	}
}
0