結果

問題 No.346 チワワ数え上げ問題
ユーザー hhgfhn1hhgfhn1
提出日時 2018-10-23 00:35:44
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 498 bytes
コンパイル時間 2,813 ms
コンパイル使用メモリ 73,796 KB
実行使用メモリ 42,208 KB
最終ジャッジ日時 2024-04-29 20:43:48
合計ジャッジ時間 8,021 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
39,600 KB
testcase_01 AC 112 ms
40,932 KB
testcase_02 AC 99 ms
39,832 KB
testcase_03 AC 111 ms
40,896 KB
testcase_04 AC 118 ms
41,316 KB
testcase_05 AC 110 ms
41,164 KB
testcase_06 AC 105 ms
40,836 KB
testcase_07 AC 99 ms
41,272 KB
testcase_08 AC 108 ms
41,496 KB
testcase_09 AC 96 ms
39,644 KB
testcase_10 WA -
testcase_11 AC 147 ms
41,608 KB
testcase_12 WA -
testcase_13 AC 157 ms
41,876 KB
testcase_14 AC 107 ms
41,224 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 162 ms
41,816 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 113 ms
40,696 KB
testcase_24 AC 115 ms
41,256 KB
testcase_25 AC 99 ms
41,024 KB
権限があれば一括ダウンロードができます

ソースコード

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