結果

問題 No.182 新規性の虜
ユーザー chankou0920
提出日時 2017-10-17 16:25:26
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 85 ms / 5,000 ms
コード長 811 bytes
コンパイル時間 2,723 ms
コンパイル使用メモリ 103,296 KB
実行使用メモリ 25,984 KB
最終ジャッジ日時 2024-12-27 19:41:39
合計ジャッジ時間 5,595 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;

public class Program {
	public static void Main(string[] args) {
		Console.ReadLine(); // n
		string[] s = Console.ReadLine().Split(' ');
		
		// int型配列に変換し、ソートする。
		int[] array = new int[s.Length];
		for (int i = 0; i < array.Length; i++) {
			array[i] = int.Parse(s[i]);
		}
		Array.Sort(array);
		
		int count = 0;
		for (int i = 0; i < array.Length; i++) {
			if (array.Length == 1) {
				count = 1;
				break;
			}
			// 前後が同じ値でなければ新規性がある。
			if (i == 0) {
				if (array[i] != array[i+1]) {
					count++;
				}
			} else if (i == array.Length - 1) {
				if (array[i] != array[i-1]) {
					count++;
				}
			} else if (array[i] != array[i-1] && array[i] != array[i+1]) {
				count++;
			}
		}
		
		Console.WriteLine(count);
	}
}
0