結果

問題 No.289 数字を全て足そう
コンテスト
ユーザー jimano
提出日時 2018-01-06 17:38:41
言語 Java
(openjdk 27 + ACL)
コンパイル:
javac -J-Duser.language=en -encoding UTF8 -cp /opt/aclib/ac_library.jar _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true -cp .:/opt/aclib/ac_library.jar _class_
結果
AC  
実行時間 68 ms / 1,000 ms
+ 678µs
コード長 802 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,354 ms
コンパイル使用メモリ 86,020 KB
実行使用メモリ 43,808 KB
最終ジャッジ日時 2026-10-06 10:59:11
合計ジャッジ時間 5,177 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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;
	}
}
0