SHOW:
|
|
- or go back to the newest paste.
| 1 | using System; | |
| 2 | ||
| 3 | class PriceChangeAlert | |
| 4 | {
| |
| 5 | static void Main() | |
| 6 | {
| |
| 7 | int n = int.Parse(Console.ReadLine()); | |
| 8 | ||
| 9 | double granica = double.Parse(Console.ReadLine()); | |
| 10 | double last = double.Parse(Console.ReadLine()); | |
| 11 | ||
| 12 | for (int i = 0; i < n - 1; i++) | |
| 13 | {
| |
| 14 | double c = double.Parse(Console.ReadLine()); | |
| 15 | double div = Proc(last, c); | |
| 16 | bool isSignificantDifference = imaliDif(div, granica); | |
| 17 | string message = Get(c, last, div, isSignificantDifference); | |
| 18 | Console.WriteLine(message); | |
| 19 | last = c; | |
| 20 | } | |
| 21 | } | |
| 22 | ||
| 23 | private static string Get(double c, double last, double razlika, bool etherTrueOrFalse) | |
| 24 | {
| |
| 25 | ||
| 26 | string to = ""; | |
| 27 | if (razlika == 0) | |
| 28 | {
| |
| 29 | to = string.Format("NO CHANGE: {0}", c);
| |
| 30 | } | |
| 31 | else if (!etherTrueOrFalse) | |
| 32 | {
| |
| 33 | to = string.Format("MINOR CHANGE: {0} to {1} ({2:F2}%)", last, c, razlika);
| |
| 34 | } | |
| 35 | else if (etherTrueOrFalse && (razlika > 0)) | |
| 36 | {
| |
| 37 | to = string.Format("PRICE UP: {0} to {1} ({2:F2}%)", last, c, razlika);
| |
| 38 | } | |
| 39 | else if (etherTrueOrFalse && (razlika < 0)) | |
| 40 | to = string.Format("PRICE DOWN: {0} to {1} ({2:F2}%)", last, c, razlika);
| |
| 41 | return to; | |
| 42 | } | |
| 43 | ||
| 44 | private static bool imaliDif(double granica, double isDiff) | |
| 45 | {
| |
| 46 | if (Math.Abs(granica/100) >= isDiff) | |
| 47 | {
| |
| 48 | return true; | |
| 49 | } | |
| 50 | return false; | |
| 51 | } | |
| 52 | ||
| 53 | private static double Proc(double l, double c) | |
| 54 | {
| |
| 55 | ||
| 56 | double r = (c - l) / l; | |
| 57 | return r*100; | |
| 58 | } | |
| 59 | } |