BetinaUKTC

5.2

Jun 2nd, 2020
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.08 KB | None | 0 0
  1. ХИСТОГРАМА
  2. import java.util.Scanner;
  3. public class main {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.         int n = scan.nextInt();
  7.         double p1 = 0;
  8.         double p2 = 0;
  9.         double p3 = 0;
  10.         double p4 = 0;
  11.         double p5 = 0;
  12.         for (int  i = 0;  i < n;  i++) {
  13.             int num = scan.nextInt();
  14.             if (num < 200){
  15.                 p1++;
  16.             }else if (num>=200 && num<400){
  17.                 p2++;
  18.             }else if (num>=400 && num<600){
  19.                 p3++;
  20.             }else if (num>=600 && num<800){
  21.                 p4++;
  22.             }else if (num>=800){
  23.                 p5++;
  24.             }
  25.         }
  26.         p1 = (p1/n)*100;
  27.         p2 = (p2/n)*100;
  28.         p3 = (p3/n)*100;
  29.         p4 = (p4/n)*100;
  30.         p5 = (p5/n)*100;
  31.         System.out.printf("%.2f%%%n%.2f%%%n%.2f%%%n%.2f%%%n%.2f%%%n",p1,p2,p3,p4,p5);
  32.     }
  33. }
  34. УМНАТА ЛИЛИ
  35. import java.util.Scanner;
  36. public class main {
  37.     public static void main(String[] args) {
  38.         Scanner scan = new Scanner(System.in);
  39.         int years = scan.nextInt();
  40.         double priceMachine = scan.nextDouble();
  41.         int toyPrice = scan.nextInt();
  42.        // int toys = 0;
  43.         int savedMoney = 0;
  44.         int birthdayMoney = 10;
  45.         for (int i = 1; i <= years; i++) {
  46.             if (i % 2 == 0) {
  47.                savedMoney += (birthdayMoney-1);
  48.                birthdayMoney+=10;
  49.             }else if (i%2==1){
  50.                savedMoney+=toyPrice;
  51.             }
  52.         }
  53.         if (savedMoney >= priceMachine){
  54.             System.out.printf("Yes! %.2f",savedMoney - priceMachine);
  55.         }else{
  56.             System.out.printf("No! %.2f",priceMachine-savedMoney);
  57.         }
  58.     }
  59. }
  60. ЗАВРЪЩАНЕ В МИНАЛОТО
  61. import java.util.Scanner;
  62. public class main {
  63.     public static void main(String[] args) {
  64.         Scanner scan = new Scanner(System.in);
  65.         double money = scan.nextDouble();
  66.         int year = scan.nextInt();
  67.         int StartYear = 1800;
  68.         int age = 18;
  69.         for (StartYear = 1800; StartYear <= year; StartYear++) {
  70.             if (StartYear % 2 == 0) {
  71.                 money -= 12000;
  72.             }
  73.             else {
  74.                 money = money-(12000 + 50 * age);
  75.             }
  76.             age++;
  77.         }
  78.         if(money>=0) {
  79.             System.out.printf("Yes! He will live a carefree life and will have %.2f dollars left.",money);
  80.         }else {
  81.             money =Math.abs(money);
  82.             System.out.printf("He will need %.2f dollars to survive.",money);
  83.         }
  84.     }
  85. }
  86. БОЛНИЦА
  87. import java.util.Scanner;
  88. public class main {
  89.     public static void main(String[] args) {
  90.         Scanner scan = new Scanner(System.in);
  91.         int days = scan.nextInt();
  92.         int treated = 0;
  93.         int untreated = 0;
  94.         int doctors = 7;
  95.         for (int i = 1; i <= days; i++) {
  96.             int patients = scan.nextInt();
  97.             if (i%3==0 && (untreated>treated)){
  98.                 doctors++;
  99.             }
  100.             if (patients>doctors){
  101.                 treated+=doctors;
  102.                 untreated += patients-doctors;
  103.             }else {
  104.                 treated += patients;
  105.             }
  106.         }
  107.         System.out.println("Treated patients: "+treated+".");
  108.         System.out.println("Untreated patients: "+untreated+".");
  109.     }
  110. }
  111. ДЕЛЕНИЕ БЕЗ ОСТАТЪК
  112. import java.util.Scanner;
  113.  
  114. public class main {
  115.     public static void main(String[] args) {
  116.         Scanner scan = new Scanner(System.in);
  117.         int n = scan.nextInt();
  118.         double p1 = 0;
  119.         double p2 = 0;
  120.         double p3 = 0;
  121.         for (int i = 0; i < n ; i++) {
  122.             int num = scan.nextInt();
  123.             if(num%2 == 0){
  124.                 p1++;
  125.             }
  126.             if(num%3 == 0){
  127.                 p2++;
  128.             }
  129.             if(num%4 == 0){
  130.                 p3++;
  131.             }
  132.         }
  133.         p1 = (p1/n)*100;
  134.         p2 = (p2/n)*100;
  135.         p3 = (p3/n)*100;
  136.         System.out.printf("%.2f%% %n",p1);
  137.         System.out.printf("%.2f%% %n",p2);
  138.         System.out.printf("%.2f%% %n",p3);
  139.     }
  140. }
  141. ЛОГИСТИКА
  142. import java.util.Scanner;
  143. public class main {
  144.     public static void main(String[] args) {
  145.         Scanner scan = new Scanner(System.in);
  146.         int count = scan.nextInt();
  147.         double busTons = 0;
  148.         double truckTons = 0;
  149.         double trainTons = 0;
  150.         double price = 0;
  151.         int allTons= 0;
  152.         for (int i = 0; i < count; i++) {
  153.             int tons = scan.nextInt();
  154.             allTons+=tons;
  155.             if (tons<=3){
  156.                 busTons+=tons;
  157.             }else if(tons > 3 && tons<=11){
  158.                 truckTons+=tons;
  159.             }else if(tons > 11){
  160.                 trainTons+=tons;
  161.             }
  162.         }
  163.         price = (busTons*200 +truckTons*175+trainTons*120)/allTons;
  164.         busTons = (busTons/allTons)*100;
  165.         truckTons = (truckTons/allTons)*100;
  166.         trainTons = (trainTons/allTons)*100;
  167.         System.out.printf("%.2f%n",price);
  168.         System.out.printf("%.2f%%%n",busTons);
  169.         System.out.printf("%.2f%%%n",truckTons);
  170.         System.out.printf("%.2f%%",trainTons);
  171.     }
  172. }
Add Comment
Please, Sign In to add comment