結果

問題 No.430 文字列検索
ユーザー kondo_raion_Nokondo_raion_No
提出日時 2016-10-03 23:36:11
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 1,737 ms / 2,000 ms
コード長 626 bytes
コンパイル時間 12,121 ms
コンパイル使用メモリ 431,796 KB
実行使用メモリ 68,572 KB
最終ジャッジ日時 2024-04-30 12:19:30
合計ジャッジ時間 31,811 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 350 ms
55,380 KB
testcase_01 AC 1,549 ms
68,572 KB
testcase_02 AC 1,324 ms
67,700 KB
testcase_03 AC 1,176 ms
67,760 KB
testcase_04 AC 350 ms
55,332 KB
testcase_05 AC 346 ms
55,168 KB
testcase_06 AC 347 ms
55,180 KB
testcase_07 AC 353 ms
55,244 KB
testcase_08 AC 431 ms
57,420 KB
testcase_09 AC 371 ms
57,624 KB
testcase_10 AC 417 ms
57,576 KB
testcase_11 AC 1,649 ms
67,820 KB
testcase_12 AC 1,614 ms
67,604 KB
testcase_13 AC 1,605 ms
67,740 KB
testcase_14 AC 1,552 ms
67,544 KB
testcase_15 AC 1,553 ms
68,312 KB
testcase_16 AC 1,737 ms
68,264 KB
testcase_17 AC 1,561 ms
68,144 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:4:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^

ソースコード

diff #

import java.util.*
import java.util.regex.Pattern

fun main(args: Array<String>) {

    val scanner = Scanner(System.`in`)
    val s = scanner.next()
    val m = scanner.nextInt()
    val C = ArrayList<String>()
    for (i in 0..m - 1) C.add(scanner.next())
    scanner.close()

    var sum = 0
    for (pattern in C) {
        sum += matchNumber(Pattern.compile(pattern), s)
    }
    println(sum)
}

fun matchNumber(pattern: Pattern, target: String): Int {
    val m = pattern.matcher(target)
    var count = 0
    if (m.find()) {
        count += 1
        while (m.find(m.start() + 1)) count += 1
    }
    return count
}
0