WeeAIResearch's picture
Release Phoenix-69B-A6.6B: v21 coding-restored GGUF
7428366 verified
Raw History Blame Contribute Delete
2.98 kB
```csharp
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
public class Program
{
public static void Main(string[] args)
{
try
{
string input = Console.In.ReadToEnd();
if (string.IsNullOrWhiteSpace(input))
{
Console.Error.WriteLine("Error: Empty input");
Environment.Exit(1);
}
JsonDocument doc;
try
{
doc = JsonDocument.Parse(input);
}
catch (JsonException ex)
{
Console.Error.WriteLine($"Error: Invalid JSON - {ex.Message}");
Environment.Exit(1);
return;
}
if (doc.RootElement.ValueKind != JsonValueKind.Array)
{
Console.Error.WriteLine("Error: Input is not a JSON array");
Environment.Exit(1);
return;
}
var elements = doc.RootElement.EnumerateArray();
int count = 0;
long sum = 0;
int? min = null;
int? max = null;
foreach (var element in elements)
{
if (element.ValueKind != JsonValueKind.Number)
{
Console.Error.WriteLine("Error: Element is not a number");
Environment.Exit(1);
return;
}
int value;
try
{
value = element.GetInt32();
}
catch (OverflowException)
{
Console.Error.WriteLine("Error: Element is out of range for 32-bit integer");
Environment.Exit(1);
return;
}
catch (InvalidOperationException)
{
Console.Error.WriteLine("Error: Element is not an integer");
Environment.Exit(1);
return;
}
count++;
sum += value;
if (min == null || value < min)
{
min = value;
}
if (max == null || value > max)
{
max = value;
}
}
var result = new
{
count = count,
sum = sum,
min = min,
max = max
};
var options = new JsonSerializerOptions
{
WriteIndented = false
};
string json = JsonSerializer.Serialize(result, options);
Console.WriteLine(json);
}
catch (Exception ex)
{
Console.Error.WriteLine($"Error: {ex.Message}");
Environment.Exit(1);
}
}
}
```