結果
問題 |
No.193 筒の数式
|
ユーザー |
|
提出日時 | 2016-11-13 12:29:50 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 22 ms / 1,000 ms |
コード長 | 1,016 bytes |
コンパイル時間 | 4,356 ms |
コンパイル使用メモリ | 102,144 KB |
実行使用メモリ | 17,664 KB |
最終ジャッジ日時 | 2024-11-25 21:54:42 |
合計ジャッジ時間 | 2,090 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; class Tsutsu { public static void Main(string[] args) { string S = Console.ReadLine(); int max = int.MinValue; string s, t; s = S.Substring(0, 1); t = S.Substring(S.Length-1, 1); if(s != "+" && s!= "-" && t!= "+" && t != "-") max = calc(S); for(int i=0; i<S.Length-1; i++) { s = S.Substring(i,1); t = S.Substring(i+1, 1); if(s != "+" && s!= "-" && t!= "+" && t != "-") { string cut = S.Substring(i+1) + S.Substring(0, i+1); max = Math.Max(max, calc(cut)); } } Console.WriteLine(max); } static int calc(string exp) { int result=0; int val = 0; int op = 0; for(int i=0; i<exp.Length; i++) { string s = exp.Substring(i, 1); if(s == "+" || s == "-") { if(op == 0) result += val; else result -= val; val = 0; if(s == "+") op = 0; else op = 1; } else { val *= 10; val += int.Parse(s); } } if(op == 0) result += val; else result -= val; return result; } }