結果

問題 No.289 数字を全て足そう
ユーザー Daigo HIROOKADaigo HIROOKA
提出日時 2018-05-11 04:23:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 251 ms / 1,000 ms
コード長 577 bytes
コンパイル時間 3,261 ms
コンパイル使用メモリ 72,956 KB
実行使用メモリ 60,696 KB
最終ジャッジ日時 2023-09-10 12:15:01
合計ジャッジ時間 9,228 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
56,076 KB
testcase_01 AC 117 ms
55,812 KB
testcase_02 AC 119 ms
56,372 KB
testcase_03 AC 118 ms
55,860 KB
testcase_04 AC 117 ms
55,700 KB
testcase_05 AC 189 ms
59,352 KB
testcase_06 AC 193 ms
59,140 KB
testcase_07 AC 226 ms
59,796 KB
testcase_08 AC 229 ms
59,588 KB
testcase_09 AC 183 ms
59,680 KB
testcase_10 AC 199 ms
59,448 KB
testcase_11 AC 213 ms
58,092 KB
testcase_12 AC 233 ms
57,676 KB
testcase_13 AC 204 ms
59,776 KB
testcase_14 AC 233 ms
59,048 KB
testcase_15 AC 219 ms
59,956 KB
testcase_16 AC 204 ms
59,832 KB
testcase_17 AC 222 ms
60,696 KB
testcase_18 AC 237 ms
59,444 KB
testcase_19 AC 221 ms
59,228 KB
testcase_20 AC 214 ms
59,988 KB
testcase_21 AC 118 ms
55,932 KB
testcase_22 AC 234 ms
59,600 KB
testcase_23 AC 251 ms
59,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class SumNum{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String numstr = sc.next();
        String[] ns = numstr.split("");

        int sum_ = 0;
        for(int i=0; i<ns.length; i++){
            Pattern p = Pattern.compile("^[0-9]+$");
            Matcher m = p.matcher(ns[i]);
            if(m.find()){
                sum_ += Integer.parseInt(ns[i]);
            }
        }
        System.out.println(sum_);
    }
}


0