結果

問題 No.289 数字を全て足そう
ユーザー jimanojimano
提出日時 2018-01-06 17:34:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 113 ms / 1,000 ms
コード長 868 bytes
コンパイル時間 3,369 ms
コンパイル使用メモリ 71,356 KB
実行使用メモリ 56,252 KB
最終ジャッジ日時 2023-08-24 22:19:17
合計ジャッジ時間 6,631 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
49,796 KB
testcase_01 AC 52 ms
49,896 KB
testcase_02 AC 52 ms
50,332 KB
testcase_03 AC 52 ms
49,952 KB
testcase_04 AC 51 ms
49,884 KB
testcase_05 AC 87 ms
52,764 KB
testcase_06 AC 79 ms
52,348 KB
testcase_07 AC 108 ms
55,676 KB
testcase_08 AC 105 ms
55,220 KB
testcase_09 AC 75 ms
52,452 KB
testcase_10 AC 93 ms
53,824 KB
testcase_11 AC 104 ms
53,500 KB
testcase_12 AC 111 ms
55,204 KB
testcase_13 AC 99 ms
53,588 KB
testcase_14 AC 111 ms
55,652 KB
testcase_15 AC 103 ms
56,252 KB
testcase_16 AC 100 ms
53,416 KB
testcase_17 AC 105 ms
56,208 KB
testcase_18 AC 113 ms
55,820 KB
testcase_19 AC 107 ms
54,480 KB
testcase_20 AC 108 ms
55,604 KB
testcase_21 AC 53 ms
50,328 KB
testcase_22 AC 112 ms
54,636 KB
testcase_23 AC 112 ms
55,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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) {
			Matcher matcher = p.matcher(s);
			if (matcher.find()) {
				sum += Integer.parseInt(s);
			}
			else {
				sum += 0;
			}
		}
		return sum;
	}
}
0