Advertisement
Sim0o0na

04. Credit System

Apr 30th, 2018
979
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _04CreditSystem
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             var n = int.Parse(Console.ReadLine());
  11.  
  12.             double sum = 0;
  13.             double credits = 0;
  14.  
  15.             for (int i = 0; i < n; i++)
  16.             {
  17.  
  18.                 var input = Console.ReadLine();
  19.  
  20.                 char c = input.Last();
  21.                 int grade = int.Parse(c.ToString());
  22.                 sum += grade;
  23.                 var credit = double.Parse(input.TrimEnd(c));
  24.  
  25.                 switch (grade)
  26.                 {
  27.                     case 2:
  28.                         credit = 0;
  29.                         break;
  30.                     case 3:
  31.                         credit = credit / 2;
  32.                         break;
  33.                     case 4:
  34.                         credit = credit * 0.7;
  35.                         break;
  36.                     case 5:
  37.                         credit = credit * 0.85;
  38.                         break;
  39.  
  40.                 }
  41.                 credits += credit;
  42.             }
  43.             Console.WriteLine("{0:f2}", credits);
  44.             Console.WriteLine("{0:f2}", sum / n);
  45.  
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement