Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace simpleArrays
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<double> frequences = Console.ReadLine().Split().Select(double.Parse).ToList();
- List<string> notes = new List<string>{"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" };
- List<double> freq = new List<double>{ 261.63, 277.18, 293.66, 311.13, 329.63, 349.23, 369.99, 392.0, 415.30, 440.0, 466.16, 493.88 };
- List<string> resNotes = getNotes(notes,freq,frequences);
- List<string> resNaturals = getNaturals(resNotes);
- List<string> resSharps = getSharp(resNotes);
- double naturalSum = getSumNat(resNaturals,freq,notes);
- double sharplSum = getSumSharp(resSharps, freq, notes);
- Console.WriteLine("Notes: {0}", string.Join(" ", resNotes));
- Console.WriteLine("Naturals: {0}", string.Join(", ", resNaturals));
- Console.WriteLine("Sharps: {0}", string.Join(", ", resSharps));
- Console.WriteLine("Naturals sum: {0}", naturalSum);
- Console.WriteLine("Sharps sum: {0}", sharplSum);
- }
- private static double getSumSharp(List<string> resSharps, List<double> freq, List<string> notes)
- {
- double a = 0.0;
- for (int i = 0; i < resSharps.Count; i++)
- {
- for (int j = 0; j < notes.Count; j++)
- {
- int b = 0;
- if (resSharps.Contains(notes[j]))
- {
- b = notes.IndexOf(resSharps[i]);
- a += freq[b];
- }
- }
- }
- return a;
- }
- private static double getSumNat(List<string> resNaturals, List<double> freq, List<string> notes)
- {
- double a = 0.0;
- for (int i = 0; i < resNaturals.Count; i++)
- {
- for (int j = 0; j < notes.Count; j++)
- {
- int b = 0;
- if (resNaturals.Contains(notes[j]))
- {
- b = notes.IndexOf(resNaturals[i]);
- a += freq[b];
- break;
- }
- }
- }
- return a;
- }
- private static List<string> getSharp(List<string> resNOtes)
- {
- List<string> a = new List<string>();
- for (int i = 0; i < resNOtes.Count; i++)
- {
- if (resNOtes[i].Length > 1)
- {
- a.Add(resNOtes[i]);
- }
- }
- return a;
- }
- private static List<string> getNaturals(List<string> resNOtes)
- {
- List<string> a = new List<string>();
- for (int i = 0; i < resNOtes.Count; i++)
- {
- if (resNOtes[i].Length == 1)
- {
- a.Add(resNOtes[i]);
- }
- }
- return a;
- }
- private static List<string> getNotes(List<string> notes, List<double> freq, List<double> frequences)
- {
- List<string> a = new List<string>();
- int indexNote = 0;
- for (int i = 0; i < frequences.Count; i++)
- {
- if (freq.Contains(frequences[i]))
- {
- indexNote = freq.IndexOf(frequences[i]);
- }
- a.Add(notes[indexNote]);
- }
- return a;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement