結果

問題 No.193 筒の数式
ユーザー suppy193suppy193
提出日時 2015-06-18 15:36:03
言語 Ruby
(3.3.0)
結果
AC  
実行時間 80 ms / 1,000 ms
コード長 770 bytes
コンパイル時間 341 ms
コンパイル使用メモリ 11,264 KB
実行使用メモリ 15,320 KB
最終ジャッジ日時 2023-09-21 09:27:33
合計ジャッジ時間 2,593 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
15,180 KB
testcase_01 AC 76 ms
15,248 KB
testcase_02 AC 76 ms
15,172 KB
testcase_03 AC 78 ms
15,084 KB
testcase_04 AC 80 ms
15,208 KB
testcase_05 AC 77 ms
15,036 KB
testcase_06 AC 78 ms
15,124 KB
testcase_07 AC 78 ms
15,252 KB
testcase_08 AC 77 ms
15,172 KB
testcase_09 AC 77 ms
15,320 KB
testcase_10 AC 76 ms
15,136 KB
testcase_11 AC 75 ms
15,172 KB
testcase_12 AC 76 ms
15,244 KB
testcase_13 AC 76 ms
15,172 KB
testcase_14 AC 76 ms
15,300 KB
testcase_15 AC 76 ms
15,116 KB
testcase_16 AC 75 ms
15,268 KB
testcase_17 AC 76 ms
15,136 KB
testcase_18 AC 76 ms
15,132 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

s = gets.chomp
#p s
max = -Float::INFINITY
(0...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
#			p ope
#			p s2
			if ope == '+'
				sum += s2.to_i
			else
#				p ope
				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
#	p sum
	max = [sum, max].max
end
p max
0