結果
| 問題 |
No.193 筒の数式
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-04-26 22:43:40 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,331 bytes |
| コンパイル時間 | 1,060 ms |
| コンパイル使用メモリ | 113,988 KB |
| 実行使用メモリ | 26,088 KB |
| 最終ジャッジ日時 | 2024-07-05 03:09:43 |
| 合計ジャッジ時間 | 2,030 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 11 WA * 5 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace Test
{
static class Program
{
static void Main(string[] args)
{
Scanner cin = new Scanner();
string expr = cin.Next();
int ans = 0;
for (int i = 0; i < expr.Length; i++)
{
string left = expr.Substring(0, i);
string right = expr.Substring(i);
string temp = right + left;
int val = Eval(temp);
ans = Math.Max(ans, Eval(temp));
}
Console.WriteLine(ans);
}
static int Eval(string expr)
{
if (expr[0] == '+' || expr[expr.Length - 1] == '+') return 0;
if (expr[0] == '-' || expr[expr.Length - 1] == '-') return 0;
List<char> op = new List<char>();
foreach (var item in expr)
{
if (item == '+' || item == '-')
{
op.Add(item);
}
}
string[] vals = expr.Split('+', '-');
int res = int.Parse(vals[0]);
for (int i = 0; i < vals.Length - 1; i++)
{
if (op[i] == '+')
{
res += int.Parse(vals[i + 1]);
}
else
{
res -= int.Parse(vals[i + 1]);
}
}
return res;
}
}
class Scanner
{
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner()
{
s = new string[0];
i = 0;
}
public string Next()
{
if (i < s.Length) return s[i++];
string st = Console.ReadLine();
while (st == "") st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return s[i++];
}
public int NextInt()
{
return int.Parse(Next());
}
public long NextLong()
{
return long.Parse(Next());
}
public double NextDouble()
{
return double.Parse(Next());
}
}
}