結果
問題 |
No.289 数字を全て足そう
|
ユーザー |
|
提出日時 | 2015-12-03 19:20:09 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 250 ms / 1,000 ms |
コード長 | 827 bytes |
コンパイル時間 | 6,587 ms |
コンパイル使用メモリ | 75,440 KB |
実行使用メモリ | 48,168 KB |
最終ジャッジ日時 | 2024-10-08 00:31:53 |
合計ジャッジ時間 | 9,649 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
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; } }