Aborigenius

Note Stats

Jun 29th, 2017
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.95 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 NoteStats
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<string> initialNotes = new List<string>(new string[] { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" });
  14.             List<double> notesFreqs = new List<double>(new double[] { 261.63, 277.18, 293.66, 311.13, 329.63, 349.23, 369.99, 392.00, 415.30, 440.00, 466.16, 493.88 });
  15.  
  16.             double[] inputFreqs = Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
  17.             List<string> totalNotes = new List<string>();
  18.             List<string> naturals = new List<string>();
  19.             List<string> sharps = new List<string>();
  20.             double naturalsSum = 0;
  21.             double sharpsSum = 0;
  22.  
  23.             for (int i = 0; i < inputFreqs.Length; i++)
  24.             {
  25.                 int index = notesFreqs.IndexOf(inputFreqs[i]);
  26.                 string currentNote = initialNotes[index];
  27.                 double freq = notesFreqs[index];
  28.  
  29.                 totalNotes.Add(currentNote);
  30.                 if (IsNatural(currentNote))
  31.                 {
  32.                     naturals.Add(currentNote);
  33.                     naturalsSum += freq;
  34.                 }
  35.                 else
  36.                 {
  37.                     sharps.Add(currentNote);
  38.                     sharpsSum += freq;
  39.                 }
  40.             }
  41.             Console.WriteLine($"Notes: {string.Join(" ", totalNotes)}");
  42.             Console.WriteLine($"Naturals: {string.Join(", ", naturals)}");
  43.             Console.WriteLine($"Sharps: {string.Join(", ", sharps)}");
  44.             Console.WriteLine($"Naturals sum: {naturalsSum}");
  45.             Console.WriteLine($"Sharps sum: {sharpsSum}");
  46.         }
  47.         static bool IsNatural(string currentNote)
  48.         {
  49.             return (currentNote.Length == 1);
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment