結果
問題 | No.222 引き算と足し算 |
ユーザー |
![]() |
提出日時 | 2025-04-09 11:09:53 |
言語 | C# (.NET 8.0.404) |
結果 |
AC
|
実行時間 | 62 ms / 1,000 ms |
コード長 | 1,185 bytes |
コンパイル時間 | 8,005 ms |
コンパイル使用メモリ | 172,104 KB |
実行使用メモリ | 187,704 KB |
最終ジャッジ日時 | 2025-04-09 11:10:04 |
合計ジャッジ時間 | 10,882 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (135 ミリ秒)。 main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
class Program { static void Main(string[] args) { char[] mark = { '+', '-' }; string formulaStr = Console.ReadLine(); int plusIndex = formulaStr.IndexOf(mark[0],1); int minusIndex = formulaStr.IndexOf(mark[1],1); var select = SelectionSymbol(plusIndex,minusIndex); string[] numList = formulaStr.Split(mark); int numA = int.Parse(formulaStr.Substring(0, select.indexNumber)); int numB = int.Parse(formulaStr.Substring(select.indexNumber + 1, formulaStr.Length - 1 - select.indexNumber )); if (select.symbol == mark[0]) { Console.WriteLine(numA-numB); } else { Console.WriteLine(numA+numB); } } private static (char symbol, int indexNumber) SelectionSymbol(int plusIndex, int minusIndex) { if (minusIndex < 0 ||plusIndex != -1 && plusIndex < minusIndex) { return ('+', plusIndex); } else { return ('-', minusIndex); } } }