結果

問題 No.289 数字を全て足そう
ユーザー rf141rf141
提出日時 2015-12-03 19:20:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 252 ms / 1,000 ms
コード長 827 bytes
コンパイル時間 3,629 ms
コンパイル使用メモリ 75,968 KB
実行使用メモリ 47,456 KB
最終ジャッジ日時 2024-04-16 20:57:24
合計ジャッジ時間 9,286 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
41,316 KB
testcase_01 AC 128 ms
41,332 KB
testcase_02 AC 131 ms
41,352 KB
testcase_03 AC 131 ms
41,168 KB
testcase_04 AC 130 ms
41,220 KB
testcase_05 AC 197 ms
44,716 KB
testcase_06 AC 185 ms
43,832 KB
testcase_07 AC 231 ms
46,476 KB
testcase_08 AC 222 ms
46,660 KB
testcase_09 AC 192 ms
44,536 KB
testcase_10 AC 205 ms
46,180 KB
testcase_11 AC 221 ms
46,476 KB
testcase_12 AC 230 ms
46,644 KB
testcase_13 AC 199 ms
46,384 KB
testcase_14 AC 220 ms
47,048 KB
testcase_15 AC 210 ms
46,500 KB
testcase_16 AC 212 ms
46,288 KB
testcase_17 AC 225 ms
46,732 KB
testcase_18 AC 233 ms
47,048 KB
testcase_19 AC 223 ms
46,252 KB
testcase_20 AC 212 ms
46,620 KB
testcase_21 AC 115 ms
40,100 KB
testcase_22 AC 228 ms
46,648 KB
testcase_23 AC 252 ms
47,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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