Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Histogram
- {
- class Program
- {
- static void Main(string[] args)
- {
- int num = int.Parse(Console.ReadLine());
- double p1 = 0;
- double p2 = 0;
- double p3 = 0;
- double p4 = 0;
- double p5 = 0;
- for (int i = 0; i < num; i++)
- {
- double n = double.Parse(Console.ReadLine());
- if (n < 200)
- {
- p1++;
- }
- else if (n < 400)
- {
- p2++;
- }
- else if (n < 600)
- {
- p3++;
- }
- else if (n < 800)
- {
- p4++;
- }
- else
- {
- p5++;
- }
- }
- Console.WriteLine($"{p1 / num * 100:F2}%");
- Console.WriteLine($"{p2 / num * 100:F2}%");
- Console.WriteLine($"{p3 / num * 100:F2}%");
- Console.WriteLine($"{p4 / num * 100:F2}%");
- Console.WriteLine($"{p5 / num * 100:F2}%");
- }
- }
- }
- РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
- using System;
- using System.Collections.Generic;
- namespace Histogram
- {
- class Program
- {
- static void Main(string[] args)
- {
- int num = int.Parse(Console.ReadLine());
- double p1 = 0;
- double p2 = 0;
- double p3 = 0;
- double p4 = 0;
- double p5 = 0;
- for (int i = 0; i < num; i++)
- {
- double n = double.Parse(Console.ReadLine());
- _ = n < 200 ? p1++ : n < 400 ? p2++ : n < 600 ? p3++ : n < 800 ? p4++ : p5++;
- }
- Console.WriteLine($"{p1 / num * 100:F2}%");
- Console.WriteLine($"{p2 / num * 100:F2}%");
- Console.WriteLine($"{p3 / num * 100:F2}%");
- Console.WriteLine($"{p4 / num * 100:F2}%");
- Console.WriteLine($"{p5 / num * 100:F2}%");
- }
- }
- }
- РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР И FOREACH:
- using System;
- using System.Collections.Generic;
- namespace Histogram
- {
- class Program
- {
- static void Main(string[] args)
- {
- int num = int.Parse(Console.ReadLine());
- double p1 = 0;
- double p2 = 0;
- double p3 = 0;
- double p4 = 0;
- double p5 = 0;
- for (int i = 0; i < num; i++)
- {
- double n = double.Parse(Console.ReadLine());
- _ = n < 200 ? p1++ : n < 400 ? p2++ : n < 600 ? p3++ : n < 800 ? p4++ : p5++;
- }
- foreach (var p in new[] { p1, p2, p3, p4, p5 })
- {
- Console.WriteLine($"{p / num * 100:F2}%");
- }
- }
- }
- }
- РЕШЕНИЕ С МАСИВ И ТЕРНАРЕН ОПЕРАТОР:
- using System;
- namespace Histogram
- {
- class Program
- {
- static void Main(string[] args)
- {
- int num = int.Parse(Console.ReadLine());
- double [] p = new[] { 0.0, 0.0, 0.0, 0.0, 0.0 };
- for (int i = 0; i < num; i++)
- {
- double n = double.Parse(Console.ReadLine());
- p[n < 200 ? 0 : n < 400 ? 1 : n < 600 ? 2 : n < 800 ? 3 : 4]++;
- }
- for (int i = 0; i < p.Length; i++)
- {
- Console.WriteLine($"{p[i] / num * 100:F2}%");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement