Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace DomashnoHistogram
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- // count numbers
- int p1 = 0; // <200
- int p2 = 0; // >=200 <=399
- int p3 = 0; // >=400 <=599
- int p4 = 0; // >=600 <=799
- int p5 = 0; // >=800
- for (int i = 0; i < n; i++)
- {
- int input = int.Parse(Console.ReadLine());
- if (input < 200)
- {
- p1++;
- }
- else if (input >= 200 && input <= 399)
- {
- p2++;
- }
- else if (input >= 400 && input <= 599)
- {
- p3++;
- }
- else if (input >= 600 && input <= 799)
- {
- p4++;
- }
- else
- {
- p5++;
- }
- }
- // calculate percentage
- int pSum = p1 + p2 + p3 + p4 + p5;
- double p1Percent = 0.0;
- double p2Percent = 0.0;
- double p3Percent = 0.0;
- double p4Percent = 0.0;
- double p5Percent = 0.0;
- if (p1 > 0)
- {
- p1Percent = 1.00 * p1 / pSum * 100;
- }
- if (p2 > 0)
- {
- p2Percent = 1.00 * p2 / pSum * 100;
- }
- if (p3 > 0)
- {
- p3Percent = 1.00 * p3 / pSum * 100;
- }
- if (p4 > 0)
- {
- p4Percent = 1.00 * p4 / pSum * 100;
- }
- if (p5 > 0)
- {
- p5Percent = 1.00 * p5 / pSum * 100;
- }
- // print
- Console.WriteLine($"{p1Percent:f2}%");
- Console.WriteLine($"{p2Percent:f2}%");
- Console.WriteLine($"{p3Percent:f2}%");
- Console.WriteLine($"{p4Percent:f2}%");
- Console.WriteLine($"{p5Percent:f2}%");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement