結果

問題 No.193 筒の数式
ユーザー bluemeganebluemegane
提出日時 2018-10-02 09:26:51
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 28 ms / 1,000 ms
コード長 1,129 bytes
コンパイル時間 855 ms
コンパイル使用メモリ 113,072 KB
実行使用メモリ 26,900 KB
最終ジャッジ日時 2024-04-20 14:28:45
合計ジャッジ時間 2,062 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
24,716 KB
testcase_01 AC 27 ms
24,968 KB
testcase_02 AC 26 ms
24,720 KB
testcase_03 AC 25 ms
24,716 KB
testcase_04 AC 28 ms
24,752 KB
testcase_05 AC 27 ms
26,892 KB
testcase_06 AC 27 ms
26,780 KB
testcase_07 AC 27 ms
26,648 KB
testcase_08 AC 27 ms
25,004 KB
testcase_09 AC 27 ms
24,852 KB
testcase_10 AC 26 ms
22,452 KB
testcase_11 AC 27 ms
26,644 KB
testcase_12 AC 27 ms
22,840 KB
testcase_13 AC 27 ms
24,716 KB
testcase_14 AC 28 ms
24,720 KB
testcase_15 AC 28 ms
26,900 KB
testcase_16 AC 27 ms
24,604 KB
testcase_17 AC 27 ms
24,984 KB
testcase_18 AC 26 ms
24,720 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System.Collections.Generic;
using System.Linq;
using System;

public class Hello
{
    public static void Main()
    {
        var ans = new List<int>();
        var s = Console.ReadLine().Trim();
        var sL = s.Length;
        var t = s;
        for (int i = 0; i < sL; i++)
        {
            if (t[0] != '+' && t[0] != '-' && t[sL - 1] != '+' && t[sL - 1] != '-')
                ans.Add(getAns(t));
            t = t.Substring(1) + t[0];
        }
        Console.WriteLine(ans.Max());
    }
    public static int getAns(string s)
    {
        string[] s2 = s.Split('+', '-');
        var a = new List<int>();
        for (int i = 0; i < s2.Length; i++)
            a.Add(int.Parse(s2[i]));
        var b = new List<int>();
        for (int i = 0; i < s.Length; i++)
            if (s[i] == '+') b.Add(0);
            else if (s[i] == '-') b.Add(1);
        int ans;
        if (b[0] == 0) ans = a[0] + a[1];
        else ans = a[0] - a[1];
        for (int i = 1; i < b.Count(); i++)
        {
            if (b[i] == 0) ans += a[i + 1];
            else ans -= a[i + 1];
        }
        return ans;
    }
}
0