結果
問題 | No.708 (+ー)の式 |
ユーザー | バカらっく |
提出日時 | 2018-07-01 12:14:18 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,547 bytes |
コンパイル時間 | 3,740 ms |
コンパイル使用メモリ | 102,864 KB |
実行使用メモリ | 22,860 KB |
最終ジャッジ日時 | 2023-09-13 16:34:04 |
合計ジャッジ時間 | 5,368 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 55 ms
20,668 KB |
testcase_01 | AC | 55 ms
22,848 KB |
testcase_02 | AC | 55 ms
20,944 KB |
testcase_03 | AC | 56 ms
22,860 KB |
testcase_04 | AC | 55 ms
20,824 KB |
testcase_05 | AC | 55 ms
20,848 KB |
testcase_06 | AC | 55 ms
20,724 KB |
testcase_07 | AC | 55 ms
20,728 KB |
testcase_08 | AC | 55 ms
20,740 KB |
testcase_09 | AC | 54 ms
22,700 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 55 ms
20,740 KB |
testcase_14 | AC | 55 ms
20,736 KB |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public void Proc() { string inpt = Reader.ReadLine(); string[] splt = DivideKakko(inpt); for (int i = 0; i < splt.Length; i++) { if(splt[i].Contains('(')) { splt[i] = GetCalc(splt[i]).ToString(); } } int ans = GetCalc(string.Join("", splt)); Console.WriteLine(ans); } private int GetCalc(string inpt) { string src = inpt; if(inpt[0] == '(') { src = inpt.Substring(1, inpt.Length - 2); } int ans = 0; bool isAdd = true; for (int i = 0; i < src.Length; i++) { if(src[i] == '-') { isAdd = false; } else if(src[i] == '+') { isAdd = true; } else if(isAdd) { ans += src[i] - '0'; } else { ans -= src[i] - '0'; } } return ans; } private string[] DivideKakko(String inText) { List<String> ret = new List<string>(); if(!inText.Contains(')')) { ret.Add(inText); return ret.ToArray(); } int stIdx = 0; for (int i = 0; i < inText.Length; i++) { if(inText[i] == '(' && i>0) { ret.Add(inText.Substring(stIdx, i - stIdx)); stIdx = i; } else if(inText[i] == ')') { ret.Add(inText.Substring(stIdx, i - stIdx + 1)); stIdx = i + 1; } } if(stIdx< inText.Length) { ret.Add(inText.Substring(stIdx, inText.Length - stIdx)); } return ret.ToArray(); } public class Reader { static StringReader sr; public static bool IsDebug = false; public static string ReadLine() { if (IsDebug) { if (sr == null) { sr = new StringReader(InputText.Trim()); } return sr.ReadLine(); } else { return Console.ReadLine(); } } private static string InputText = @" 1-(2-1)+(2+2)-3 "; } public static void Main(string[] args) { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }