結果
| 問題 |
No.346 チワワ数え上げ問題
|
| コンテスト | |
| ユーザー |
n120aosssssssss
|
| 提出日時 | 2017-05-14 22:11:05 |
| 言語 | PHP (843.2) |
| 結果 |
AC
|
| 実行時間 | 48 ms / 2,000 ms |
| コード長 | 533 bytes |
| コンパイル時間 | 308 ms |
| コンパイル使用メモリ | 31,088 KB |
| 実行使用メモリ | 31,396 KB |
| 最終ジャッジ日時 | 2024-09-16 05:52:20 |
| 合計ジャッジ時間 | 2,295 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
コンパイルメッセージ
No syntax errors detected in Main.php
ソースコード
<?php
$string = trim(fgets(STDIN));
//文字数
$length = strlen($string);
//指定開始位置からwの数
$allwCnt = countW($string, $length);
//チワワの数
$cwCnt = 0;
for($i = 0; $i < $length; $i++) {
if($string[$i] === 'c') {
$cwCnt += $allwCnt * ($allwCnt - 1) / 2;
} else if($string[$i] === 'w') {
$allwCnt--;
}
}
echo $cwCnt;
echo PHP_EOL;
function countW($string, $length) {
$wCnt = 0;
for($i = 0; $i < $length; $i++) {
if($string[$i] === 'w') {
$wCnt++;
}
}
return $wCnt;
}
n120aosssssssss