結果
| 問題 | No.289 数字を全て足そう |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-01-06 17:38:41 |
| 言語 | Java (openjdk 25.0.2) |
| 結果 |
AC
|
| 実行時間 | 69 ms / 1,000 ms |
| コード長 | 802 bytes |
| 記録 | |
| コンパイル時間 | 3,358 ms |
| コンパイル使用メモリ | 82,616 KB |
| 実行使用メモリ | 42,324 KB |
| 最終ジャッジ日時 | 2026-05-29 10:01:09 |
| 合計ジャッジ時間 | 5,492 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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;
}
}