Advertisement
n4wn4w

DICTIONARY zadacha

May 14th, 2015
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.90 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication28
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.  
  14.             SortedDictionary<string, SortedDictionary<string, double>> dataDictionary =
  15.                                             new SortedDictionary<string, SortedDictionary<string, double>>();
  16.  
  17.             SortedDictionary<string, SortedDictionary<string, double>> dataO =
  18.                                             new SortedDictionary<string, SortedDictionary<string, double>>();
  19.  
  20.             int dataLinesNumber = int.Parse(Console.ReadLine());
  21.            
  22.             string lineContents = String.Empty;
  23.             string[] lineTokens;
  24.             string student = "";
  25.             string predmet = String.Empty;
  26.             int ocenka = 0;
  27.             int count = 2;
  28.             for (int i = 0; i < dataLinesNumber; i++)
  29.             {
  30.                 lineContents = Console.ReadLine();
  31.                 lineTokens = lineContents.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  32.                 student = (lineTokens[0]) + " " +(lineTokens[1]);
  33.                
  34.                 predmet = lineTokens[2];
  35.                 ocenka = int.Parse(lineTokens[3]);
  36.  
  37.                 if (!dataDictionary.ContainsKey(student))
  38.                 {
  39.                     dataDictionary[student] = new SortedDictionary<string, double>();
  40.                 }
  41.  
  42.                 if (!dataDictionary[student].ContainsKey(predmet))
  43.                 {
  44.                     count = 1;
  45.                     dataDictionary[student][predmet] = count;
  46.                    
  47.                    
  48.                 }
  49.                 else
  50.                 {
  51.                    
  52.                     dataDictionary[student][predmet] = ++count;
  53.                    
  54.                 }
  55.                 /////////////////// 2 dictionary
  56.                  if (!dataO.ContainsKey(student))
  57.                 {
  58.                     dataO[student] = new SortedDictionary<string, double>();
  59.                 }
  60.  
  61.                 if (!dataO[student].ContainsKey(predmet))
  62.                 {
  63.                     dataO[student][predmet] = ocenka;
  64.                  
  65.                 }
  66.                 else
  67.                 {
  68.                     dataO[student][predmet] += ocenka;
  69.                    
  70.                 }
  71.  
  72.  
  73.             }
  74.  
  75.  
  76.             ////////////////////////////////////////
  77.  
  78.             int kondio = 0;
  79.  
  80.             bool kur = true;
  81.  
  82.             int avg = 0;
  83.             double sum = 0;
  84.             bool isFirstPair = true;
  85.  
  86.  
  87.  
  88.             foreach (var cityPair in dataDictionary)
  89.             {
  90.                 Console.Write(cityPair.Key + ": ");
  91.                 foreach (var venuePair in cityPair.Value)
  92.                 {
  93.                     kondio++;
  94.                     avg += 2;
  95.                     //  if (kondio == 1 || kondio == 4)
  96.                     //    {
  97.                     if (kondio % 2 != 0)
  98.                     {
  99.                         Console.Write("->{0}:", venuePair.Key); // , String.Join(", ", venuePair.Value)
  100.                         foreach (var item in dataO)
  101.                         {
  102.                             foreach (var em in item.Value)
  103.                             {
  104.                                 if (kondio % 2 != 0)
  105.                                 {
  106.                                     //    if (avg == 1 || avg == 8)
  107.                                     //     {
  108.                                     sum = em.Value / venuePair.Value;
  109.                                     Console.Write(" -- > {0:0.00}, ", sum);
  110.                                     //  }
  111.                                 }
  112.                             }
  113.                         }
  114.                         //  }
  115.                     }
  116.                 }
  117.             }
  118.       }
  119.      }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement