結果

問題 No.222 引き算と足し算
ユーザー Lycoris_i
提出日時 2015-09-08 22:06:20
言語 Ruby
(3.4.1)
結果
WA  
実行時間 -
コード長 906 bytes
コンパイル時間 74 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-11-15 22:04:21
合計ジャッジ時間 3,827 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18 WA * 13
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

xopy = gets.chomp.split(//)
if xopy.index("-") == 0
  if xopy.index("+") != nil
    x = xopy[0..xopy.index("+") - 1].join.to_i
    y = xopy[xopy.index("+") + 1..-1].join.to_i
    puts x - y
  else
    x = xopy[1..xopy[1..-1].index("-") - 1].join.to_i
    y = xopy[xopy[1..-1].index("-") + 1..-1].join.to_i
    puts x + y
  end
elsif xopy.index("+") == 0
  if xopy[1..-1].index("+") != nil
    x = xopy[0..xopy[1..-1].index("+") - 1].join.to_i
    y = xopy[xopy[1..-1].index("+") + 1..-1].join.to_i
    puts x - y
  else
    x = xopy[0..xopy.index("-") - 1].join.to_i
    y = xopy[xopy.index("-") + 1..-1].join.to_i
    puts x + y
  end
else
  if xopy.index("+") != nil
    x = xopy[0..xopy.index("+") - 1].join.to_i
    y = xopy[xopy.index("+") + 1..-1].join.to_i
    puts x - y
  else
    x = xopy[0..xopy.index("-") - 1].join.to_i
    y = xopy[xopy.index("-") + 1..-1].join.to_i
    puts x + y
  end
end
0