結果

問題 No.346 チワワ数え上げ問題
ユーザー hhgfhn1hhgfhn1
提出日時 2018-10-23 00:36:57
言語 Java21
(openjdk 21)
結果
AC  
実行時間 699 ms / 2,000 ms
コード長 501 bytes
コンパイル時間 3,312 ms
コンパイル使用メモリ 75,248 KB
実行使用メモリ 42,272 KB
最終ジャッジ日時 2024-04-29 20:44:31
合計ジャッジ時間 10,075 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
39,736 KB
testcase_01 AC 111 ms
39,960 KB
testcase_02 AC 121 ms
41,168 KB
testcase_03 AC 123 ms
41,192 KB
testcase_04 AC 126 ms
41,248 KB
testcase_05 AC 123 ms
41,272 KB
testcase_06 AC 127 ms
41,252 KB
testcase_07 AC 126 ms
41,388 KB
testcase_08 AC 126 ms
40,920 KB
testcase_09 AC 128 ms
41,236 KB
testcase_10 AC 194 ms
42,264 KB
testcase_11 AC 239 ms
41,700 KB
testcase_12 AC 247 ms
42,028 KB
testcase_13 AC 220 ms
41,224 KB
testcase_14 AC 154 ms
40,924 KB
testcase_15 AC 232 ms
42,040 KB
testcase_16 AC 212 ms
41,904 KB
testcase_17 AC 237 ms
42,272 KB
testcase_18 AC 196 ms
41,852 KB
testcase_19 AC 214 ms
41,676 KB
testcase_20 AC 197 ms
41,764 KB
testcase_21 AC 675 ms
41,904 KB
testcase_22 AC 699 ms
41,980 KB
testcase_23 AC 121 ms
40,992 KB
testcase_24 AC 121 ms
40,848 KB
testcase_25 AC 121 ms
41,064 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;
		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