結果
問題 |
No.346 チワワ数え上げ問題
|
ユーザー |
![]() |
提出日時 | 2016-02-27 00:05:54 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 997 bytes |
コンパイル時間 | 2,323 ms |
コンパイル使用メモリ | 74,508 KB |
実行使用メモリ | 62,144 KB |
最終ジャッジ日時 | 2024-09-24 10:40:24 |
合計ジャッジ時間 | 13,198 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 3 |
other | AC * 11 WA * 9 TLE * 1 -- * 2 |
ソースコード
import java.util.Scanner; public class Main { public static void main(String[] args) { try (Scanner scan = new Scanner(System.in)) { String S = scan.nextLine(); int ans = 0; for(int i=0; i<S.length(); i++) { if(S.charAt(i) == 'c') { int count = 0; for(int j=i+1; j<S.length(); j++) { if(S.charAt(j) == 'w') { count++; } } if(count >= 2) { int tmp = 0; for(int j=count-1; j>=1; j--) { tmp += j; } ans += tmp; } } } if(ans == 0) { System.out.println(-1); } else { System.out.println(ans); } } } }