結果

問題 No.708 (+ー)の式
ユーザー NoNo
提出日時 2018-07-09 23:47:27
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 1,486 bytes
コンパイル時間 2,772 ms
コンパイル使用メモリ 105,824 KB
実行使用メモリ 26,516 KB
最終ジャッジ日時 2023-09-25 00:51:33
合計ジャッジ時間 5,303 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
22,372 KB
testcase_01 AC 101 ms
24,428 KB
testcase_02 AC 101 ms
24,504 KB
testcase_03 AC 97 ms
24,208 KB
testcase_04 AC 102 ms
26,384 KB
testcase_05 AC 102 ms
26,516 KB
testcase_06 AC 102 ms
22,516 KB
testcase_07 AC 103 ms
24,460 KB
testcase_08 AC 104 ms
26,456 KB
testcase_09 AC 103 ms
24,540 KB
testcase_10 AC 102 ms
26,508 KB
testcase_11 AC 102 ms
24,688 KB
testcase_12 AC 100 ms
24,552 KB
testcase_13 AC 102 ms
26,484 KB
testcase_14 AC 96 ms
24,312 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Text.RegularExpressions;
namespace y
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            int a = 0;
            while (!int.TryParse(s, out a))
            {
                s = s.Replace("--", "+").Replace("+-", "-");
                s = Ca(s);
            }

            Console.WriteLine(a);
        }

        static string Ca(string s)
        {
            string a = Regex.Match(s, @"\(.*?\)").Value;
            if (a.Length == 0) a = s;

            int r = 0;
            bool isMinus = false;
            for (int j = 0; j < a.Length; j++)
            {
                if (a[j] == '-')
                {
                    isMinus = true;
                    continue;
                }

                if (a[j] >= '0' && a[j] <= '9')
                {
                    string y = a[j].ToString();
                    while (j < a.Length - 1 && (a[j + 1] >= '0' && a[j + 1] <= '9'))
                    {
                        y += a[j + 1];
                        j++;
                    }

                    if (!isMinus)
                    {
                        r += int.Parse(y);
                    }
                    else
                    {
                        r -= int.Parse(y);
                        isMinus = false;
                    }
                }
            }
            return s.Replace(a, r.ToString());
        }
    }
}
0