-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA. IQ test.cs
72 lines (58 loc) · 1.88 KB
/
A. IQ test.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication20
{
class Program
{
static void Main(string[] args)
{
reader = Console.In;
writer = Console.Out;
var init = ReadInt();
var nums = ReadIntList();
var maxN = nums.Count(x => x == nums.Max());
var minN = nums.Count(x => x == nums.Min());
Console.Write(nums.Max() - nums.Min() + " ");
Write(nums.Distinct().Count() <= 1 ? init * (init - 1) / 2 : maxN * minN);
Console.ReadLine();
}
// Utility finctions. Reader
private static Queue<string> currentLineTokens = new Queue<string>();
protected static TextReader reader;
protected static TextWriter writer;
private static string[] ReadAndSplitLine()
{
return reader.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
}
public static string ReadToken()
{
if (currentLineTokens.Count == 0)
currentLineTokens = new Queue<string>(ReadAndSplitLine());
return currentLineTokens.Dequeue();
}
public static int ReadInt()
{
return int.Parse(ReadToken());
}
public static int[] ReadIntArray()
{
return ReadAndSplitLine().Select(int.Parse).ToArray();
}
public static List<int> ReadIntList()
{
return ReadAndSplitLine().Select(int.Parse).ToList();
}
//Utility functions.Writer
public static void Write (params object [] array)
{
WriteArray(array);
}
public static void WriteArray<T> (IEnumerable<T> array)
{
writer.WriteLine(string.Join(" ", array));
}
}
}