Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.BigDecimal;
- import java.math.BigInteger;
- import java.util.Scanner;
- /**
- * Created by ChaosFire on 13.11.2017 г.
- */
- public class AnonymousDownSite {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int websitesDown = Integer.parseInt(scanner.nextLine());
- BigInteger securityKey = new BigInteger(scanner.nextLine());//направо в BigInteger, ползва се само за изчислението на токена
- String[] name = new String[websitesDown];
- BigDecimal[] price = new BigDecimal[websitesDown];//а не double, 20 знака след запетаята, double пази 15-16, няма нужда от setScale
- BigDecimal[] multiply = new BigDecimal[websitesDown];
- for (int i = 0; i < websitesDown ; i++) {
- name[i] = scanner.next();
- //Премахваш visits напълно, парсването към int е ненужно, защото после веднага парсваш към BigDecimal
- BigDecimal visitCount = new BigDecimal(scanner.next());
- price[i] = new BigDecimal(scanner.next());
- multiply[i] = price[i].multiply(visitCount);
- }
- scanner.close();
- BigDecimal total = BigDecimal.ZERO;//имаш константа за нулева стойност, по-добре е да я използваш
- for (int i = 0; i < websitesDown; i++) {
- total = total.add(multiply[i]);
- }
- for (String start : name){
- System.out.println(start);
- }
- BigInteger securityToken = securityKey.pow(websitesDown);//а не double, double не е достатъчно голям тип
- System.out.printf("Total Loss: %.20f%n", total);
- System.out.printf("Security Token: %d", securityToken);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement