Advertisement
Guest User

notes

a guest
Jun 25th, 2017
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.17 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. class NoteStatistics
  7. {
  8.     static void Main(string[] args)
  9.     {
  10.         List<decimal> frecs = Console.ReadLine().Split(' ').Select(decimal.Parse).ToList();
  11.  
  12.         Dictionary<decimal, string> notes = new Dictionary<decimal, string>()
  13.         {
  14.             {261.63M,"C"},
  15.             {277.18M,"C#"},
  16.             {293.66M,"D"},
  17.             {311.13M,"D#"},
  18.             {329.63M,"E"},
  19.             {349.23M,"F"},
  20.             {369.99M,"F#"},
  21.             {392M,"G"},
  22.             {415.3M,"G#"},
  23.             {440M,"A"},
  24.             {466.16M,"A#"},
  25.             {493.88M,"B"},
  26.         };
  27.  
  28.         string[] note = new string[frecs.Count];
  29.         List<string> naturals = new List<string>();
  30.         List<string> sharps = new List<string>();
  31.         decimal sumNaturals = new decimal();
  32.         decimal sumSharps = new decimal();
  33.         int counter = 0;
  34.  
  35.         foreach (var item in frecs/*notes*/)
  36.         {
  37.             //if (counter < frecs.Count)
  38.             //{
  39.                 if (notes.ContainsKey(frecs[counter]))
  40.                 {
  41.                     //notes.TryGetValue(frecs[counter], out note[counter]);
  42.                     note[counter] = notes[item];
  43.                     if (note[counter].Length == 1)
  44.                     {
  45.                         naturals.Add(note[counter]);
  46.                         sumNaturals += frecs[counter];
  47.                     }
  48.                     else //if (note[counter].Last() == '#')
  49.                     {
  50.                         sharps.Add(note[counter]);
  51.                         sumSharps += frecs[counter];
  52.                     }
  53.                 }
  54.                 counter++;
  55.             //}
  56.             //else
  57.             //{
  58.             //    break;
  59.             //}
  60.         }
  61.         Console.WriteLine($"Notes: {string.Join(" ", note)}");
  62.         Console.WriteLine($"Naturals: {string.Join(", ", naturals)}");
  63.         Console.WriteLine($"Sharps: {string.Join(", ", sharps)}");
  64.         Console.WriteLine($"Naturals sum: {sumNaturals}");
  65.         Console.WriteLine($"Sharps sum: {sumSharps}");
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement