結果
問題 |
No.365 ジェンガソート
|
ユーザー |
![]() |
提出日時 | 2018-06-11 11:34:26 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 90 ms / 2,000 ms |
コード長 | 2,675 bytes |
コンパイル時間 | 3,361 ms |
コンパイル使用メモリ | 104,576 KB |
実行使用メモリ | 25,472 KB |
最終ジャッジ日時 | 2024-06-30 13:30:13 |
合計ジャッジ時間 | 4,713 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 41 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; namespace JengaSort { class Program { static void Main(string[] args) { //ブロックの個数をNで定義 int N = InputN(1, 100000); //それぞれのブロックの長さをEachLength配列で定義 int[] EachLength = Input(N, 1, N); int Result = Processing(N , EachLength); int Answer = N - Result; Console.WriteLine(Answer); } //1行目の入力が数字で行われているか、数値は指定の範囲内のものかを判定 static int InputN(int Min , int Max) { int Number = 0; try { Number = int.Parse(Console.ReadLine()); if (Number < Min || Number > Max) { Console.WriteLine(Min + "以上" + Max + "以下で入力してください"); } }catch(FormatException e) { Console.WriteLine("数字を入力してください"); }catch(Exception E) { Console.WriteLine("想定外のエラーです"); } return Number; } //2行目の入力が数字で行われているか、数値は指定の範囲内のものかを判定 static int[] Input(int N ,int Min , int Max) { String[] Numbers = null; try { Numbers = Console.ReadLine().Split(); for(int i = 0; i < N; i++) { if(int.Parse(Numbers[i]) < Min || int.Parse(Numbers[i]) > Max) { Console.WriteLine(Min + "以上" + Max + "以下の数字で入力してください"); } } } catch(Exception E) { Console.WriteLine("想定外のエラーです"); } //String型配列をint型配列に変換 int[] NewNumbers = new int[N]; for (int j = 0; j < N; j++) { NewNumbers[j] = int.Parse(Numbers[j]); } return NewNumbers; } //移動がない数字の個数を計算するメソッド static int Processing(int N , int[] EachLength) { //変動しない数字の個数をCount変数で数える int Count = 0; //変動する最大を更新して所持する変数 int Match = N; for (int i = N - 1; i >= 0; i--) { if(EachLength[i] == Match) { Count++; Match--; } } return Count; } } }