Advertisement
Guest User

AnonymousDownSite

a guest
Nov 13th, 2017
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.88 KB | None | 0 0
  1. import java.math.BigDecimal;
  2. import java.math.BigInteger;
  3. import java.util.Scanner;
  4.  
  5. /**
  6.  * Created by ChaosFire on 13.11.2017 г.
  7.  */
  8. public class AnonymousDownSite {
  9.  
  10.     public static void main(String[] args) {
  11.         Scanner scanner = new Scanner(System.in);
  12.  
  13.         int websitesDown = Integer.parseInt(scanner.nextLine());
  14.         BigInteger securityKey = new BigInteger(scanner.nextLine());//направо в BigInteger, ползва се само за изчислението на токена
  15.  
  16.         String[] name = new String[websitesDown];
  17.         BigDecimal[] price = new BigDecimal[websitesDown];//а не double, 20 знака след запетаята, double пази 15-16, няма нужда от setScale
  18.         BigDecimal[] multiply = new BigDecimal[websitesDown];
  19.  
  20.         for (int i = 0; i < websitesDown ; i++) {
  21.             name[i] = scanner.next();
  22.             //Премахваш visits напълно, парсването към int е ненужно, защото после веднага парсваш към BigDecimal
  23.             BigDecimal visitCount = new BigDecimal(scanner.next());
  24.             price[i] = new BigDecimal(scanner.next());
  25.             multiply[i] = price[i].multiply(visitCount);
  26.         }
  27.         scanner.close();
  28.  
  29.         BigDecimal total = BigDecimal.ZERO;//имаш константа за нулева стойност, по-добре е да я използваш
  30.         for (int i = 0; i < websitesDown; i++) {
  31.             total = total.add(multiply[i]);
  32.         }
  33.         for (String start : name){
  34.             System.out.println(start);
  35.         }
  36.         BigInteger securityToken = securityKey.pow(websitesDown);//а не double, double не е достатъчно голям тип
  37.         System.out.printf("Total Loss: %.20f%n", total);
  38.         System.out.printf("Security Token: %d", securityToken);
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement