結果

問題 No.193 筒の数式
ユーザー suppy193suppy193
提出日時 2015-06-18 15:16:03
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 718 bytes
コンパイル時間 59 ms
コンパイル使用メモリ 11,384 KB
実行使用メモリ 15,408 KB
最終ジャッジ日時 2023-09-21 09:26:42
合計ジャッジ時間 2,748 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

s = gets.chomp
p s
max = 0
(1...s.length).each do |i|
#	print s[0, i], " ", s[i..-1], "\n"
	s2 = s[i..-1] + s[0, i]
	next if s2[0] == '+' || s2[0] == '-' || s2[-1] == '+' || s2[-1] == '-'
	p s2
	sum = 0
	ope_index = s2.index(/[+|-]/)
	sum = s2[0, ope_index].to_i
#	p sum
	ope = s2[ope_index]
#	p ope
	s2 = s2[ope_index+1..-1]
#	p s2
	while s2 != nil
#	p ope
#	p s2
		ope_index = s2.index(/[+|-]/)
#		p ope_index
		if !ope_index
			if ope == '+'
				sum += s2.to_i
			else
				sum -= s2.to_i
			end
			break
		else
			if ope == '+'
				sum += s2[0..ope_index - 1].to_i
			else
				sum -= s2[0..ope_index - 1].to_i
			end
			ope = s2[ope_index]
			s2 = s2[ope_index + 1..-1]
		end
	end
	max = [sum, max].max
end
puts max
0