Ronka

Untitled

Jun 7th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. using System;
  2.  
  3. class PriceChangeAlert
  4. {
  5. static void Main()
  6. {
  7. int n = int.Parse(Console.ReadLine());
  8. double threshold = double.Parse(Console.ReadLine());
  9. double last = double.Parse(Console.ReadLine());
  10. for (int i = 0; i < n - 1; i++)
  11. {
  12. double price = double.Parse(Console.ReadLine());
  13. double diff = Proc(last, price);
  14. bool isSignificantDifference = isDiff(diff, threshold);
  15. string message = Get(price, last, diff, isSignificantDifference);
  16. Console.WriteLine(message);
  17. last = price;
  18. }
  19. }
  20. private static string Get(double price, double last, double change, bool etherTrueOrFalse)
  21. {
  22. string result = "";
  23. if (change == 0)
  24. {
  25. result = string.Format("NO CHANGE: {0}", price);
  26. }
  27. else if (!etherTrueOrFalse)
  28. {
  29. result = string.Format("MINOR CHANGE: {0} to {1} ({2:F2}%)", last, price, change * 100);
  30. }
  31. else if (etherTrueOrFalse && (change > 0))
  32. {
  33. result = string.Format("PRICE UP: {0} to {1} ({2:F2}%)", last, price, change * 100);
  34. }
  35. else if (etherTrueOrFalse && (change < 0))
  36. result = string.Format("PRICE DOWN: {0} to {1} ({2:F2}%)", last, price, change * 100);
  37. return result;
  38. }
  39.  
  40. private static bool isDiff(double threshold, double isDiff)
  41. {
  42. if (Math.Abs(threshold) >= isDiff)
  43. {
  44. return true;
  45. }
  46. return false;
  47. }
  48.  
  49. private static double Proc(double last, double price)
  50. {
  51. double res = (price - last) / last;
  52. return res;
  53. }
  54. }
Add Comment
Please, Sign In to add comment