結果
問題 |
No.289 数字を全て足そう
|
ユーザー |
|
提出日時 | 2018-01-06 17:38:41 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 136 ms / 1,000 ms |
コード長 | 802 bytes |
コンパイル時間 | 3,749 ms |
コンパイル使用メモリ | 74,684 KB |
実行使用メモリ | 41,908 KB |
最終ジャッジ日時 | 2024-12-23 08:41:23 |
合計ジャッジ時間 | 7,189 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.regex.Matcher; import java.util.regex.Pattern; public class No0289 { public static void main(String[] args) throws NumberFormatException, IOException { try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) { String s = br.readLine().trim(); // regex number int sum = countByRegex(s); System.out.println(sum); } catch (IOException e) { e.printStackTrace(); } } static int countByRegex(String str) { int sum = 0; String[] strArray = str.split(""); String numRegex = "\\d"; Pattern p = Pattern.compile(numRegex); for (String s : strArray) { if (p.matcher(s).find()) { sum += Integer.parseInt(s); } } return sum; } }