強さの近い馬のstrの差を求める。
EASYのラストだけど、めっちゃ簡単じゃない?
using System; using System.Linq; using System.IO; using System.Text; using System.Collections; using System.Collections.Generic; /** * Auto-generated code below aims at helping you parse * the standard input according to the problem statement. **/ class Solution { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); //お馬さんの数 int[] Pi = new int[N]; //馬のstr値を格納する配列 for (int i = 0; i < N; i++) { Pi[i] = int.Parse(Console.ReadLine()); //各馬のstr値を格納 } Array.Sort(Pi); //昇順ソート int difstr = int.MaxValue; for(int i = 0; i < N-1; i++) { int dif = Pi[i+1] - Pi[i]; //馬の個体値の差を算出 if(dif < difstr) { //より小さいstr差が見つかれば格納 difstr = dif; } } // Write an action using Console.WriteLine() // To debug: Console.Error.WriteLine("Debug messages..."); Console.WriteLine(difstr); } }
- 出版社/メーカー: 株式会社ZERO PLUS
- メディア: ヘルスケア&ケア用品
- この商品を含むブログを見る