結果

問題 No.289 数字を全て足そう
ユーザー muu16muu16
提出日時 2018-11-26 21:54:34
言語 Ruby
(3.3.0)
結果
AC  
実行時間 87 ms / 1,000 ms
コード長 649 bytes
コンパイル時間 286 ms
コンパイル使用メモリ 11,236 KB
実行使用メモリ 15,296 KB
最終ジャッジ日時 2023-09-02 07:56:54
合計ジャッジ時間 4,106 ms
ジャッジサーバーID
(参考情報)
judge11 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,176 KB
testcase_01 AC 78 ms
15,136 KB
testcase_02 AC 78 ms
15,260 KB
testcase_03 AC 79 ms
15,156 KB
testcase_04 AC 81 ms
15,296 KB
testcase_05 AC 87 ms
15,264 KB
testcase_06 AC 80 ms
15,096 KB
testcase_07 AC 84 ms
15,088 KB
testcase_08 AC 83 ms
15,180 KB
testcase_09 AC 80 ms
15,136 KB
testcase_10 AC 80 ms
15,096 KB
testcase_11 AC 80 ms
15,056 KB
testcase_12 AC 82 ms
15,260 KB
testcase_13 AC 80 ms
15,156 KB
testcase_14 AC 83 ms
15,092 KB
testcase_15 AC 79 ms
15,092 KB
testcase_16 AC 78 ms
15,296 KB
testcase_17 AC 82 ms
15,048 KB
testcase_18 AC 82 ms
15,144 KB
testcase_19 AC 81 ms
15,296 KB
testcase_20 AC 82 ms
15,168 KB
testcase_21 AC 79 ms
15,172 KB
testcase_22 AC 81 ms
15,108 KB
testcase_23 AC 83 ms
15,268 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

# 文字列𝑆が与えられるので, その中のそれぞれの
# 数字を1桁の数値とみなして, 全ての合計値を求めてください.
# 例えば1test23という文字列の数字の合計値は1+2+3=6となる.

a = gets.chomp
#入力例
# gj9ut986u1@

b = a.delete("^0-9")
#正規表現で文字列の中から数字だけを取り出す

c = b.chars
#取り出した数字を1文字1文字配列にする
#出力例
#["9", "9", "8", "6", "1"]

d = c.map(&:to_i)
#文字列になっている数字を数値に変換する
#出力例
#[9, 9, 8, 6, 1]

e = d.inject(:+)
#答え33
if e == nil
  puts "0"
else
  p d.inject(:+)
end
0