online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
using System; using System.Collections.Generic; using System.IO; using System.Linq; class Program { static void Main() { string[] lines = File.ReadAllLines("results.txt"); Dictionary<string, int> scores = new Dictionary<string, int>(); foreach (string line in lines) { // Split the line into name and score string[] parts = line.Split(':'); string name = parts[0].Trim(); int score = int.Parse(parts[1].Trim()); // If the name is already in the dictionary, keep the highest score if (scores.ContainsKey(name)) { if (score > scores[name]) { scores[name] = score; } } else { // Add new name and score scores[name] = score; } } // Use the Max method from LINQ to find the maximum key length int maxNameLength = scores.Keys.Max(k => k.Length); // Print out the highest scores for each person foreach (var entry in scores) { Console.WriteLine($"{entry.Key.PadRight(maxNameLength)}:{entry.Value.ToString().PadLeft(3)} gissningar"); } } }
Erik: 6 Anna: 7 Lars: 6 Johan: 8 Anders: 7 Anna: 10 Sofia: 5 Johan: 9 Anna: 4 Lars: 7

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue