結果

問題 No.193 筒の数式
ユーザー No
提出日時 2015-06-16 15:42:31
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 23 ms / 1,000 ms
コード長 2,162 bytes
コンパイル時間 2,548 ms
コンパイル使用メモリ 109,708 KB
実行使用メモリ 26,832 KB
最終ジャッジ日時 2024-07-07 03:19:53
合計ジャッジ時間 2,466 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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.

ソースコード

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 S = Console.ReadLine().ToList();
            int max = int.MinValue;
            for (int i = 0; i < S.Count(); i++)
            {
                if (char.IsNumber(S[0]) && char.IsNumber(S[S.Count - 1]))
                {
                    max = Math.Max(max, a(S));
                }
                S.Add(S[0]);
                S.RemoveAt(0);
            }
            Console.WriteLine(max);
        }

        static int a(List<char> s)
        {
            int i = 0;
            int re = 0;
            string x = "";
            bool isPlus = true;

            while (true)
            {
                x = "";
                while (char.IsNumber(s[i]))
                {
                    x += s[i];
                    i++;
                    if (i > s.Count - 1)
                    {
                        break;
                    }
                }

                if (isPlus)
                {
                    re += int.Parse(x);
                }
                else
                {
                    re -= int.Parse(x);
                }

                if (i > s.Count - 1)
                {
                    break;
                }

                if (s[i] == '+')
                {
                    isPlus = true;
                }
                else
                {
                    isPlus = false;
                }
                i++;
            }
            return re;
        }

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

        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