Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace StudentScoresDictionary
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> input = Console.ReadLine().Split(' ').ToList();
- var dict = new Dictionary<string, Dictionary<string, List<int>>>();
- while (input[0] != "print" || (input[0] != "print" && dict.ContainsKey(input[1])))
- {
- if (!dict.ContainsKey(input[1]))
- {
- dict.Add(input[1], new Dictionary<string, List<int>>());
- }
- if (!dict[input[1]].ContainsKey(input[2]))
- {
- dict[input[1]].Add(input[2], new List<int>());
- }
- if (input.Count == 4)
- {
- dict[input[1]][input[2]].Add(int.Parse(input[3]));
- }
- input = Console.ReadLine().Split(' ').ToList();
- }
- if (input.Count == 2 && input[0] == "print" && dict.ContainsKey(input[1]))
- {
- Console.WriteLine($"{input[1]}");
- foreach (var subject in dict[input[1]])
- {
- Console.WriteLine($"- {subject.Key}: {String.Join(", ", subject.Value)}");
- }
- }
- else if (input[0] == "print" && input.Count == 1)
- {
- foreach (var student in dict)
- {
- Console.WriteLine($"{student.Key}");
- foreach (var subject in dict[student.Key])
- {
- Console.WriteLine($"- {subject.Key}: {String.Join(", ", subject.Value)}");
- }
- }
- }
- else
- {
- throw new ArgumentException("Please provide a correct input/command!");
- }
- //dict.Add(studentName, new Dictionary<string, List<int>>());
- //dict[studentName].Add(subject, new List<int>());
- //dict[studentName][subject].Add(grades[0]); // to check with more than 1 grade
- ////dict["studentName"]["math"].Add(grade[0]);
- ////dict["studentName"]["math"].Add(grade[0]);
- //dict[studentName].Add(subject, new List<int>());
- //dict[studentName][subject].Add(5);
- //dict.Add("pesho", new Dictionary<string, List<int>>());
- //dict["pesho"].Add("chemistry", new List<int>());
- //dict["pesho"]["chemistry"].Add(2);
- }
- }
- }
Add Comment
Please, Sign In to add comment