Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace Student_Scores
- {
- class Program
- {
- static void Main(string[] args)
- {
- var studentScores = new Dictionary<string, Dictionary<string, List<int>>>();
- string[] input = Console.ReadLine().Split(" ");
- //add gosho math 2 // creates gosho, creates math for gosho, and adds 2 to the math list
- //add gosho math 3 // gosho exists, math exists, adds 3 to the math list
- //add gosho chemistry 2 // gosho exists, creates chemistry for gosho, and adds 2 to the chemistry list
- //add pesho math 4 // creates pesho, creates math for pesho, add 4 to the math list
- //add pesho chemistry 3 // pesho exists, creates chemistry for pesho, adds 3 to the chemistry list for pesho
- while (input[0] != "print")
- {
- string studentName = input[1];
- string subject = input[2];
- int score = int.Parse(input[3]);
- if (!studentScores.ContainsKey(studentName))
- {
- studentScores[studentName] = new Dictionary<string, List<int>>();
- if (!studentScores[studentName].ContainsKey(subject))
- {
- studentScores[studentName].Add(subject, new List<int>());
- studentScores[studentName][subject].Add(score);
- }
- else
- {
- studentScores[studentName][subject].Add(score);
- }
- }
- else
- {
- if (!studentScores[studentName].ContainsKey(subject))
- {
- studentScores[studentName].Add(subject, new List<int>());
- studentScores[studentName][subject].Add(score);
- }
- else
- {
- studentScores[studentName][subject].Add(score);
- }
- }
- input = Console.ReadLine().Split(" ");
- }
- var bilder = new StringBuilder();
- if(input.Length == 1)
- {
- foreach (var student in studentScores)
- {
- bilder.AppendLine(student.Key + ":");
- foreach (var item in student.Value)
- {
- bilder.AppendLine($"- {item.Key}: {string.Join(",", item.Value)}");
- }
- }
- }
- else
- {
- string name = input[1];
- foreach (var student in studentScores)
- {
- if(student.Key == name)
- {
- bilder.AppendLine(student.Key + ":");
- foreach (var item in student.Value)
- {
- bilder.AppendLine($"- {item.Key}: {string.Join(",", item.Value)}");
- }
- }
- }
- }
- Console.WriteLine(bilder.ToString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement