Advertisement
tmollov

Untitled

Feb 22nd, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace simpleArrays
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. List<double> frequences = Console.ReadLine().Split().Select(double.Parse).ToList();
  13. List<string> notes = new List<string>{"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" };
  14. 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 };
  15.  
  16. List<string> resNotes = getNotes(notes,freq,frequences);
  17. List<string> resNaturals = getNaturals(resNotes);
  18. List<string> resSharps = getSharp(resNotes);
  19. double naturalSum = getSumNat(resNaturals,freq,notes);
  20. double sharplSum = getSumSharp(resSharps, freq, notes);
  21.  
  22. Console.WriteLine("Notes: {0}", string.Join(" ", resNotes));
  23. Console.WriteLine("Naturals: {0}", string.Join(", ", resNaturals));
  24. Console.WriteLine("Sharps: {0}", string.Join(", ", resSharps));
  25. Console.WriteLine("Naturals sum: {0}", naturalSum);
  26. Console.WriteLine("Sharps sum: {0}", sharplSum);
  27. }
  28.  
  29. private static double getSumSharp(List<string> resSharps, List<double> freq, List<string> notes)
  30. {
  31. double a = 0.0;
  32. for (int i = 0; i < resSharps.Count; i++)
  33. {
  34. for (int j = 0; j < notes.Count; j++)
  35. {
  36. int b = 0;
  37. if (resSharps.Contains(notes[j]))
  38. {
  39. b = notes.IndexOf(resSharps[i]);
  40. a += freq[b];
  41. }
  42. }
  43. }
  44. return a;
  45. }
  46.  
  47. private static double getSumNat(List<string> resNaturals, List<double> freq, List<string> notes)
  48. {
  49. double a = 0.0;
  50. for (int i = 0; i < resNaturals.Count; i++)
  51. {
  52. for (int j = 0; j < notes.Count; j++)
  53. {
  54. int b = 0;
  55. if (resNaturals.Contains(notes[j]))
  56. {
  57. b = notes.IndexOf(resNaturals[i]);
  58. a += freq[b];
  59. break;
  60. }
  61. }
  62. }
  63. return a;
  64. }
  65.  
  66. private static List<string> getSharp(List<string> resNOtes)
  67. {
  68. List<string> a = new List<string>();
  69. for (int i = 0; i < resNOtes.Count; i++)
  70. {
  71. if (resNOtes[i].Length > 1)
  72. {
  73. a.Add(resNOtes[i]);
  74. }
  75. }
  76. return a;
  77. }
  78.  
  79. private static List<string> getNaturals(List<string> resNOtes)
  80. {
  81. List<string> a = new List<string>();
  82. for (int i = 0; i < resNOtes.Count; i++)
  83. {
  84. if (resNOtes[i].Length == 1)
  85. {
  86. a.Add(resNOtes[i]);
  87. }
  88. }
  89. return a;
  90. }
  91.  
  92. private static List<string> getNotes(List<string> notes, List<double> freq, List<double> frequences)
  93. {
  94. List<string> a = new List<string>();
  95. int indexNote = 0;
  96.  
  97. for (int i = 0; i < frequences.Count; i++)
  98. {
  99. if (freq.Contains(frequences[i]))
  100. {
  101. indexNote = freq.IndexOf(frequences[i]);
  102. }
  103. a.Add(notes[indexNote]);
  104. }
  105. return a;
  106. }
  107. }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement