Advertisement
Guest User

Student_Scores

a guest
Jan 23rd, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.24 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace Student_Scores
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             var studentScores = new Dictionary<string, Dictionary<string, List<int>>>();
  12.  
  13.             string[] input = Console.ReadLine().Split(" ");
  14.  
  15.             //add gosho math 2 // creates gosho, creates math for gosho, and adds 2 to the math list
  16.             //add gosho math 3 // gosho exists, math exists, adds 3 to the math list
  17.             //add gosho chemistry 2 // gosho exists, creates chemistry for gosho, and adds 2 to the chemistry list
  18.             //add pesho math 4 // creates pesho, creates math for pesho, add 4 to the math list
  19.             //add pesho chemistry 3 // pesho exists, creates chemistry for pesho, adds 3 to the chemistry list for pesho
  20.  
  21.             while (input[0] != "print")
  22.             {
  23.                 string studentName = input[1];
  24.                 string subject = input[2];
  25.                 int score = int.Parse(input[3]);
  26.  
  27.                 if (!studentScores.ContainsKey(studentName))
  28.                 {
  29.                     studentScores[studentName] = new Dictionary<string, List<int>>();
  30.  
  31.                     if (!studentScores[studentName].ContainsKey(subject))
  32.                     {
  33.                         studentScores[studentName].Add(subject, new List<int>());
  34.                         studentScores[studentName][subject].Add(score);
  35.                     }
  36.                     else
  37.                     {
  38.                         studentScores[studentName][subject].Add(score);
  39.                     }
  40.                 }
  41.                 else
  42.                 {
  43.                     if (!studentScores[studentName].ContainsKey(subject))
  44.                     {
  45.                         studentScores[studentName].Add(subject, new List<int>());
  46.                         studentScores[studentName][subject].Add(score);
  47.                     }
  48.                     else
  49.                     {
  50.                         studentScores[studentName][subject].Add(score);
  51.                     }
  52.                 }
  53.  
  54.                 input = Console.ReadLine().Split(" ");
  55.             }
  56.  
  57.             var bilder = new StringBuilder();
  58.  
  59.             if(input.Length == 1)
  60.             {
  61.                 foreach (var student in studentScores)
  62.                 {
  63.                     bilder.AppendLine(student.Key + ":");
  64.  
  65.                     foreach (var item in student.Value)
  66.                     {
  67.                         bilder.AppendLine($"- {item.Key}: {string.Join(",", item.Value)}");
  68.                     }
  69.                 }
  70.             }
  71.             else
  72.             {
  73.                 string name = input[1];
  74.  
  75.                 foreach (var student in studentScores)
  76.                 {
  77.                     if(student.Key == name)
  78.                     {
  79.                         bilder.AppendLine(student.Key + ":");
  80.  
  81.                         foreach (var item in student.Value)
  82.                         {
  83.                             bilder.AppendLine($"- {item.Key}: {string.Join(",", item.Value)}");
  84.                         }
  85.                     }
  86.                 }
  87.             }
  88.  
  89.             Console.WriteLine(bilder.ToString());
  90.         }
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement