Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace CreditSystem
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- double totalGrades = 0;
- double totalCredits = 0;
- for (int i = 0; i < n; i++)
- {
- int number = int.Parse(Console.ReadLine());
- int grade = number % 10;
- double credit = (int)number / 10;
- totalGrades += grade;
- if (grade == 2)
- {
- credit = 0;
- }
- else if (grade == 3)
- {
- credit *= 0.50;
- }
- else if (grade == 4)
- {
- credit *= 0.70;
- }
- else if (grade == 5)
- {
- credit *= 0.85;
- }
- totalCredits += credit;
- }
- Console.WriteLine($"{totalCredits:f2}\n{totalGrades / n:f2}");
- }
- }
- }
- Решение с тернарен оператор:
- using System;
- namespace CreditSystem
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- double totalGrades = 0;
- double totalCredits = 0;
- for (int i = 0; i < n; i++)
- {
- int number = int.Parse(Console.ReadLine());
- int grade = number % 10;
- double credit = (int)number / 10;
- totalGrades += grade;
- credit *=
- grade == 2 ? 0 :
- grade == 3 ? 0.50 :
- grade == 4 ? 0.75 :
- grade == 5 ? 0.85 : 1;
- totalCredits += credit;
- }
- Console.WriteLine($"{totalCredits:f2}\n{totalGrades / n:f2}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement