47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
using Spectre.Console;
|
|
|
|
namespace part1;
|
|
|
|
class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
int sum = 0;
|
|
|
|
string letters = "abcdefghijklmnopqrstuvwxyz";
|
|
|
|
var table = new Table();
|
|
table.AddColumn(new TableColumn("String"));
|
|
table.AddColumn(new TableColumn("First"));
|
|
table.AddColumn(new TableColumn("Last"));
|
|
table.AddColumn(new TableColumn("Result"));
|
|
|
|
StreamReader sr = new StreamReader("input");
|
|
String line = sr.ReadLine();
|
|
//Continue to read until you reach end of file
|
|
while (line != null)
|
|
{
|
|
line = line.ToLower();
|
|
|
|
List<int> ints = [];
|
|
|
|
for (int i = 0; i < line.Length; i++) {
|
|
if(Char.IsDigit(line[i])) {
|
|
ints.Add(Int32.Parse(line[i].ToString()));
|
|
}
|
|
}
|
|
|
|
int result = (ints.First() * 10) + ints.Last();
|
|
table.AddRow(line, ints.First().ToString(), ints.Last().ToString(), result.ToString());
|
|
|
|
sum += result;
|
|
|
|
line = sr.ReadLine();
|
|
}
|
|
//close the file
|
|
sr.Close();
|
|
AnsiConsole.Write(table);
|
|
Console.WriteLine($"Total Sum: {sum}");
|
|
}
|
|
}
|