結果

問題 No.289 数字を全て足そう
ユーザー SaYaSaYa
提出日時 2015-11-08 20:17:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 174 ms / 1,000 ms
コード長 575 bytes
コンパイル時間 2,005 ms
コンパイル使用メモリ 74,672 KB
実行使用メモリ 44,000 KB
最終ジャッジ日時 2024-04-16 19:21:39
合計ジャッジ時間 6,600 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
41,288 KB
testcase_01 AC 126 ms
41,460 KB
testcase_02 AC 125 ms
41,472 KB
testcase_03 AC 127 ms
41,192 KB
testcase_04 AC 126 ms
41,380 KB
testcase_05 AC 158 ms
41,788 KB
testcase_06 AC 151 ms
41,828 KB
testcase_07 AC 154 ms
43,144 KB
testcase_08 AC 154 ms
43,228 KB
testcase_09 AC 155 ms
41,844 KB
testcase_10 AC 156 ms
42,248 KB
testcase_11 AC 164 ms
42,724 KB
testcase_12 AC 169 ms
43,648 KB
testcase_13 AC 157 ms
42,524 KB
testcase_14 AC 171 ms
44,000 KB
testcase_15 AC 166 ms
43,212 KB
testcase_16 AC 159 ms
42,064 KB
testcase_17 AC 172 ms
43,180 KB
testcase_18 AC 171 ms
43,616 KB
testcase_19 AC 168 ms
43,208 KB
testcase_20 AC 167 ms
43,428 KB
testcase_21 AC 131 ms
41,204 KB
testcase_22 AC 174 ms
43,692 KB
testcase_23 AC 166 ms
43,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.regex.Pattern;

public class Main {

    public static void main(String[] args) {
        int answer = 0;

        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();

        Pattern pattern = Pattern.compile("^[0-9]+$");

        for (char c : s.toCharArray()) {
            String sOfC = String.valueOf(c);
            if (pattern.matcher(sOfC).matches()) {
                int i = Integer.parseInt(sOfC);
                answer += i;
            }
        }

        System.out.println(answer);
    }
}
0