結果

問題 No.289 数字を全て足そう
コンテスト
ユーザー rf141
提出日時 2015-12-03 19:20:09
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 143 ms / 1,000 ms
コード長 827 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,356 ms
コンパイル使用メモリ 84,084 KB
実行使用メモリ 51,704 KB
最終ジャッジ日時 2026-04-24 10:03:03
合計ジャッジ時間 5,944 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

public class AllNumber{
	public static void main(String... args){
		Scanner scan = new Scanner(System.in);
		String target = scan.next();
		String[] number = target.split("");
		
		for(int i = 0; i < number.length; i++){
			if(isNumber(number[i])){
				continue;
			}else{
				number[i] = "not";
			}
		}
		System.out.println(allPlus(number));

	}

	public static boolean isNumber(String str){
		String regex = "[0-9]";
		Pattern p = Pattern.compile(regex);
		Matcher m = p.matcher(str);
		return (m.find())?true:false;
	}

	public static int allPlus(String[] numberList){
		
		int result = 0;

		for(String str : numberList){
			if(str.equals("not")){
				continue;
			}
			result += Integer.parseInt(str);

		}

		return result;

	}
}
0