結果

問題 No.222 引き算と足し算
ユーザー NoNo
提出日時 2015-06-16 07:36:40
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 24 ms / 1,000 ms
コード長 2,435 bytes
コンパイル時間 838 ms
コンパイル使用メモリ 114,020 KB
実行使用メモリ 26,088 KB
最終ジャッジ日時 2024-04-27 17:41:54
合計ジャッジ時間 2,586 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
21,812 KB
testcase_01 AC 23 ms
24,020 KB
testcase_02 AC 23 ms
23,892 KB
testcase_03 AC 23 ms
25,812 KB
testcase_04 AC 23 ms
25,828 KB
testcase_05 AC 23 ms
23,784 KB
testcase_06 AC 23 ms
25,960 KB
testcase_07 AC 22 ms
23,528 KB
testcase_08 AC 23 ms
23,664 KB
testcase_09 AC 24 ms
25,696 KB
testcase_10 AC 23 ms
24,112 KB
testcase_11 AC 24 ms
26,072 KB
testcase_12 AC 23 ms
23,852 KB
testcase_13 AC 24 ms
25,960 KB
testcase_14 AC 23 ms
23,664 KB
testcase_15 AC 23 ms
23,528 KB
testcase_16 AC 22 ms
21,816 KB
testcase_17 AC 23 ms
23,916 KB
testcase_18 AC 23 ms
25,824 KB
testcase_19 AC 23 ms
25,692 KB
testcase_20 AC 24 ms
25,952 KB
testcase_21 AC 23 ms
23,852 KB
testcase_22 AC 23 ms
23,660 KB
testcase_23 AC 23 ms
23,980 KB
testcase_24 AC 24 ms
25,828 KB
testcase_25 AC 23 ms
25,812 KB
testcase_26 AC 24 ms
23,776 KB
testcase_27 AC 23 ms
23,856 KB
testcase_28 AC 23 ms
26,088 KB
testcase_29 AC 24 ms
25,808 KB
testcase_30 AC 24 ms
21,692 KB
testcase_31 AC 23 ms
23,784 KB
testcase_32 AC 24 ms
25,812 KB
testcase_33 AC 23 ms
23,908 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.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace foryuki
{
    class Program
    {
        static void Main(string[] args)
        {
            var c = (Console.ReadLine() + '\0').ToCharArray();
            string x = "";
            string y = "";
            bool isPlus1 = true;
            bool isPlus2 = true;
            bool isPlus3 = true;
            int i = 0;

            if (c[i] == '-')
            {
                isPlus1 = false;
                i++;
            }
            else if (c[i] == '+')
            {
                i++;
            }

            while (char.IsNumber(c[i]))
            {
                x += c[i];
                i++;
            }

            if (c[i] == '-' && (c[i + 1] == '+' || c[i + 1] == '-'))
            {
                isPlus2 = false;
                i++;

                if (c[i] == '-')
                {
                    isPlus3 = false;
                }
                i++;
            }
            else if (c[i] == '+' && (c[i + 1] == '+' || c[i + 1] == '-'))
            {
                i++;

                if (c[i] == '-')
                {
                    isPlus3 = false;
                }
                i++;
            }
            else if (c[i] == '+')
            {
                i++;
            }
            else if (c[i] == '-')
            {
                isPlus3 = false;
                i++;
            }

            while (char.IsNumber(c[i]))
            {
                y += c[i];
                i++;
            }

            int a = (isPlus1 ? 1 : -1) * int.Parse(x);
            int b = (isPlus3 ? 1 : -1) * int.Parse(y);

            int ans;
            if (isPlus2)
            {
                ans = a - b;
            }
            else
            {
                ans = a + b;
            }

            Console.WriteLine(ans);
        }

        //-------------------------------------------------------------

        static int[] ConvertStringArrayToIntArray(string[] array)
        {
            return Array.ConvertAll(array, str => int.Parse(str));
        }

        static List<int> ConvertStringArrayToIntList(string[] str)
        {
            var list = new List<int>();
            foreach (var c in str)
            {
                list.Add(int.Parse(c));
            }
            return list;
        }
    }
}
0