পৃষ্ঠাসমূহ

বৃহস্পতিবার, ২২ জুন, ২০১৭

10487 Closest Sums

import java.util.Scanner;

public class ClosestSum10487 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int counter = 0;
        while (scanner.hasNext()) {
            int nums = scanner.nextInt();
            if (nums == 0) break;
            counter++;
            System.out.println("Case "+counter+":");
            int numsarray[] = new int[nums];
            for (int i=0;i<nums;i++) {
                numsarray[i] = scanner.nextInt();
            }


            int testsum = 0;
            int tests = scanner.nextInt();
            for (int i=0;i<tests;i++) {
                testsum = scanner.nextInt();
                int result = 0;
                int mindiff = Integer.MAX_VALUE;
                for (int j=0;j<nums-1;j++) {
                    for (int k=j+1;k<nums;k++) {
                        if (Math.abs(numsarray[j]+numsarray[k]-testsum) < mindiff) {
                            result = numsarray[j]+numsarray[k];
                            mindiff = Math.abs(numsarray[j]+numsarray[k]-testsum);
                            
                        }
                    }
                }
                System.out.println("Closest sum to "+testsum+" is "+result+".");
            }
        }
    }
}

11247 Income Tax

import java.util.Scanner;

public class IncomeTax11247 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            double m = scanner.nextInt();
            double x = scanner.nextInt();
            if (m == 0 && x == 0) break;

            double result = ((m-1)*100)/(100-x);

            if (Double.isInfinite(result)) {
                System.out.println("Not found");
            } else {
                if (((m-1)*100)%(100-x) == 0) {
                    result = result -1;
                }
                if (result < m) {
                    System.out.println("Not found");
                } else {
                    result = Math.floor(result);
                    System.out.printf("%.0f",result);
                    System.out.println();
                }
            }


        }
    }
}

বুধবার, ২১ জুন, ২০১৭

11078 Open Credit System


import java.util.Scanner;

class Another {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int testCases = scanner.nextInt();
        while (testCases-- > 0) {
            int studentNumber = scanner.nextInt();
            int numbers[] = new int[studentNumber];
            for (int i=0;i<studentNumber;i++) {
                numbers[i] = scanner.nextInt();
            }
            
            int max = -1000000;
            int highest = -1000000;

            for (int i=0;i<numbers.length;i++) {
                int num = highest-numbers[i];
                if (num > max) max = num;
                if (numbers[i] > highest) highest = numbers[i];
            }
            System.out.println(max);
        }

    }

}

10976 Fractions Again?!

import java.util.ArrayList;
import java.util.Scanner;

class Another {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        while (scanner.hasNext()) {
            int num = scanner.nextInt();
            ArrayList<Pair> pairs = new ArrayList<>();
            for (int y=num+1;y<=(2*num);y++) {
                if ((num*y)%(num - y) == 0) {
                    int x = (num*y)/(y - num);
                    pairs.add(new Pair(x,y));
                }
            }
            System.out.println(pairs.size());
            for (Pair pair: pairs) {
                System.out.println("1/"+num+" = 1/"+pair.x+" + 1/"+pair.y);
            }

        }
    }

}
class Pair {
    int x, y;
    public Pair(int x, int y) {
        this.x = x;
        this.y = y;
    }
}

মঙ্গলবার, ২০ জুন, ২০১৭

12342 Tax Calculator

import java.util.Scanner;

class Another {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int testCases = scanner.nextInt();
        scanner.nextLine();
        int counter = 0;
        while (testCases-- > 0) {
            counter++;

            double tax = 0;
            int amount = scanner.nextInt();
            if (amount > 1180000) {
                int am = amount-1180000;
                tax += am*0.25;
                amount = 1180000;
            }
            if (amount > 880000) {
                int am = amount-880000;
                tax += am*0.20;
                amount = 880000;
            }
            if (amount > 480000) {
                int am = amount - 480000;
                tax += am*0.15;
                amount = 480000;
            }
            if (amount > 180000) {
                int am = amount - 180000;
                tax += am*0.1;
            }
            System.out.print("Case "+counter+": ");
            if (tax < 2000 && amount > 180000) {
                System.out.println(2000);
            } else {
                System.out.printf("%.0f",Math.ceil(tax));
                System.out.println();
            }
        }

    }
}

সোমবার, ১৯ জুন, ২০১৭

11219 How old are you?

import java.util.Scanner;

class Another {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int testCases = scanner.nextInt();
        scanner.nextLine();
        int counter = 0;
        while (testCases-- > 0) {
            scanner.nextLine();
            String current = scanner.nextLine();
            String birth = scanner.nextLine();

            counter++;
            System.out.print("Case #"+counter+": ");

            String cur[] = current.split("/");
            String brt[] = birth.split("/");

            int currentYear = Integer.parseInt(cur[2]);
            int currentMonth = Integer.parseInt(cur[1]);
            int currentDay = Integer.parseInt(cur[0]);

            int birthYear = Integer.parseInt(brt[2]);
            int birthMonth = Integer.parseInt(brt[1]);
            int birthDate = Integer.parseInt(brt[0]);

            int age = 0, flag = 0;

            if (currentYear >= birthYear) {
                if (currentYear == birthYear) {
                    if (currentMonth == birthMonth) {
                        if (currentDay >= birthDate) {
                            System.out.println("0");
                            flag = 1;
                        } else if (currentDay < birthDate) {
                            System.out.println("Invalid birth date");
                            flag = 1;
                        }
                    } else if (currentMonth < birthMonth) {
                        System.out.println("Invalid birth date");
                        flag = 1;
                    } else {
                        System.out.println("0");
                        flag = 1;
                    }
                } else {
                    age = currentYear - birthYear;
                    if (currentMonth < birthMonth) {
                        age -= 1;
                    } else if (currentMonth == birthMonth) {
                        if (currentDay < birthDate) {
                            age -= 1;
                        }
                    }
                }
            } else {
                System.out.println("Invalid birth date");
                flag = 1;
            }

            if (flag == 0) {
                if (age <= 130) {
                    System.out.println(age);
                } else {
                    System.out.println("Check birth date");
                }
            }

        }

    }
}

11586 Train Tracks

import java.util.Scanner;

class Another {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int testCases = scanner.nextInt();
        scanner.nextLine();
        while (testCases-- > 0) {
            String line = scanner.nextLine();
            int ms = 0, fs = 0;
            String[] arr = line.split("\\s+");
            if (arr.length == 1) {
                System.out.println("NO LOOP");
                continue;
            }
            for (int i=0;i<arr.length;i++) {
                if (arr[i].charAt(0) == 'M') ms++;
                if (arr[i].charAt(1) == 'F') fs++;
            }

            if (ms != fs) System.out.println("NO LOOP");
            else System.out.println("LOOP");
        }

    }
}

10919 Prerequisites?

import java.util.ArrayList;
import java.util.Scanner;

class Another {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        while (scanner.hasNext()) {
            int takenCourses = scanner.nextInt();
            if (takenCourses == 0) break;
            int categories = scanner.nextInt();
            ArrayList<String> takenCoursesList = new ArrayList<>();
            int flag = 1;
            scanner.nextLine();
            for (int i =0 ;i< takenCourses;i++) {
                takenCoursesList.add(scanner.next());
            }
            scanner.nextLine();
            while (categories-- > 0) {
                int total = scanner.nextInt();
                int needToTake = scanner.nextInt();
                int count = 0;

                for (int i =0 ;i< total;i++) {
                    if (takenCoursesList.contains(scanner.next())) count++;
                }
                if (count < needToTake) flag = 0;
                scanner.nextLine();
            }
            if (flag == 0) System.out.println("no");
            else System.out.println("yes");
        }

    }
}

10324 Zeros and Ones

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


class Another {
    public static void main(String[] args) throws IOException {

        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        int counter = 0;
        String line;
        while ((line = br.readLine()) != null) {
            counter++;

            if (line.equals("")) break;
            String tr = br.readLine();
            int tries = Integer.parseInt(tr);
            System.out.println("Case "+counter+":");
            while (tries-- > 0) {
                String inp = br.readLine();
                String[] arr = inp.split(" ");
                int i = Integer.parseInt(arr[0]);
                int j = Integer.parseInt(arr[1]);
                if (i>j) {
                    int temp = i;
                    i = j;
                    j = temp;
                }

                String sub = line.substring(i,j+1);
                if (sub.contains("0") && sub.contains("1")) {
                    System.out.println("No");
                } else {
                    System.out.println("Yes");
                }
            }

        }
    }
}

রবিবার, ১৮ জুন, ২০১৭

10114 Loansome Car Buyer

import java.util.*;

class Another {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        while (scanner.hasNext()) {
            int month = scanner.nextInt();
            if (month < 0) break;

            double[] rates = new double[month+1];
            double downPayment = scanner.nextDouble();
            double money = scanner.nextDouble();
            double currentOwe = money;

            double saved = money;
            int result = 0;

            int inputs = scanner.nextInt();
            for (int i=0;i<inputs;i++) {
                rates[scanner.nextInt()] = scanner.nextDouble();
            }
            double start = rates[0];
            money = money - (money*start) + (downPayment*(1-rates[0]));

            if (money > currentOwe) System.out.println("0 months");
            else {
                for (int i=1;i<=month;i++) {
                    if (rates[i] == 0) {
                        rates[i] = start;
                    } else {
                        start = rates[i];
                    }
                    currentOwe = currentOwe-(saved/month);
                    money = money - money*rates[i];

                    if (money > currentOwe) {
                        result = i;
                        break;
                    }
                }

                if (result == 1) {
                    System.out.println("1 month");
                } else {
                    System.out.println(result+" months");
                }
            }

        }
    }
}

661 Blowing Fuses

import java.util.*;

class Another {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int counter = 0;
        while (scanner.hasNext()) {
            counter++;
            int n = scanner.nextInt();
            int m = scanner.nextInt();
            int c = scanner.nextInt();
            if (n == 0 && m == 0 & c == 0) break;
            int current = 0, flag = 0, max = 0;
            int[] capacity = new int[n+1];
            for (int i=1;i<=n;i++) {
                capacity[i] = scanner.nextInt();
            }

            int[] times = new int[n+1];
            for (int i=1;i<=m;i++) {
                int num = scanner.nextInt();
                times[num]++;
                if (times[num]%2 == 0) {
                    current -= capacity[num];
                } else {
                    current += capacity[num];
                    if (current > max) max = current;
                }
            }


            System.out.println("Sequence "+counter);
            if (max <= c) {
                System.out.println("Fuse was not blown.");
                System.out.println("Maximal power consumption was "+max+" amperes.");
            } else {
                System.out.println("Fuse was blown.");
            }

            System.out.println();

        }
    }
}

10141 Request for Proposal

import java.util.*;

class Another {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int counter = 0;
        while (scanner.hasNext()) {
            counter++;
            double criteria = scanner.nextDouble();
            int proposals = scanner.nextInt();
            if (criteria == 0 && proposals == 0) break;

            scanner.nextLine();
            String selected = "", companyName;
            double factor;
            double min = Integer.MAX_VALUE;
            double maxFactor = 0;

            for (int i=0;i<criteria;i++) {
                scanner.nextLine();
            }
            while (proposals-- > 0) {

                companyName = scanner.nextLine();
                String line = scanner.nextLine();
                String[] arr = line.split(" ");
                double price = Double.parseDouble(arr[0]);
                double metCriteria = Double.parseDouble(arr[1]);
                for (int i=0;i<metCriteria;i++) {
                    scanner.nextLine();
                }
                factor = metCriteria/criteria;

                if (factor >= maxFactor) {
                    if (factor == maxFactor) {
                        if (price < min) {
                            min = price;
                            selected = companyName;
                        }
                    } else {
                        min = price;
                        selected = companyName;
                    }
                    maxFactor = factor;

                }

            }

            if (counter != 1) System.out.println();
            System.out.println("RFP #"+counter);
            System.out.println(selected);

        }
    }
}

119 Greedy Gift Givers

import java.util.*;

class Another {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int counter = 0;
        while (scanner.hasNext()) {
            int people = scanner.nextInt();
            scanner.nextLine();
            counter++;
            Map<String, Integer> moneyToAll = new HashMap<>();
            String names = scanner.nextLine();
            String[] arr = names.split(" ");
            for (int i=0;i<people;i++) {
                moneyToAll.put(arr[i], 0);
            }

            for (int i=0;i<people;i++) {
                String who = scanner.next();
                int amount = scanner.nextInt();



                int number = scanner.nextInt();
                if (number != 0){
                    moneyToAll.replace(who, moneyToAll.get(who) - amount);
                    moneyToAll.replace(who, moneyToAll.get(who) + amount%number);
                }

                for (int j = 0; j< number; j++) {
                    String p = scanner.next();
                    moneyToAll.replace(p, moneyToAll.get(p) + amount/number);
                }

            }

            if (counter != 1) {
                System.out.println();
            }

            for (String anArr : arr) {
                System.out.println(anArr + " " + moneyToAll.get(anArr));
            }


        }
    }
}

শুক্রবার, ১৬ জুন, ২০১৭

10424 Love Calculator

package uva100;


import java.util.Scanner;


public class Practice {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String name1 = scanner.nextLine();
            String name2 = scanner.nextLine();

            name1 = name1.toLowerCase();
            name2 = name2.toLowerCase();

            int name1count = 0, name2count = 0;
            for (int i=0;i<name1.length();i++) {
                char ch = name1.charAt(i);
                if (ch >='a' && ch <= 'z') {
                    name1count += (ch-96);
                }
            }

            while (name1count > 9) {
                int temp = 0;
                while (name1count > 0) {
                    temp = temp+(name1count%10);
                    name1count = name1count/10;
                }
                name1count = temp;
            }

            for (int i=0;i<name2.length();i++) {
                char ch = name2.charAt(i);
                if (ch >='a' && ch <= 'z') {
                    name2count += (ch-96);
                }
            }

            while (name2count > 9) {
                int temp = 0;
                while (name2count > 0) {
                    temp = temp+(name2count%10);
                    name2count = name2count/10;
                }
                name2count = temp;
            }

            //System.out.println("name 1: "+name1count+"name 2: "+name2count);            double res = (double) name2count/(double) name1count;
            res = res*100;
            if (res > 101) {
                res = (double) name1count/(double) name2count;
                res = res*100;
            }
            if (name1count == 0 && name2count == 0)
                System.out.println();
            else {

                    System.out.printf("%.2f",res);
                    System.out.print(" %");
                    System.out.println();

            }

        }
    }

}

বুধবার, ১৪ জুন, ২০১৭

12554 A Special "Happy Birthday" Song!!!

import java.util.ArrayList;
import java.util.Scanner;

class Another {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int people = scanner.nextInt();
        scanner.nextLine();
        ArrayList<String> persons = new ArrayList<>();
        for (int i = 0; i < people; i++) {
            persons.add(scanner.nextLine());
        }
        ArrayList<String> song = new ArrayList<>();
        song.add("Happy");
        song.add("birthday");
        song.add("to");
        song.add("you");
        song.add("Happy");
        song.add("birthday");
        song.add("to");
        song.add("you");
        song.add("Happy");
        song.add("birthday");
        song.add("to");
        song.add("Rujia");
        song.add("Happy");
        song.add("birthday");
        song.add("to");
        song.add("you");

        if (people <= 16) {
            for (int i = 0; i < song.size(); i++) {
                System.out.println(persons.get(i % persons.size()) + ": " + song.get(i));
            }
        } else {

            int extra = (persons.size() % song.size());

            for (int i = 0; i < persons.size(); i++) {
                System.out.println(persons.get(i) + ": " + song.get(i % 16));
            }

            for (int i = extra; i < 16; i++) {
                System.out.println(persons.get(i - extra) + ": " + song.get(i));
            }

        }
    }


}

12503 Robot Instructions

import java.util.ArrayList;
import java.util.Scanner;

class Another {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int testCases = scanner.nextInt();
        while (testCases-- > 0) {
            int commands = scanner.nextInt();
            int value = 0;
            ArrayList<String> cmnds = new ArrayList<>();
            scanner.nextLine();
            while (commands-- > 0) {
                String command = scanner.nextLine();
                cmnds.add(command);
                while (true) {
                    if (command.equals("LEFT")) {
                        value--;
                        break;
                    } else if (command.equals("RIGHT")) {
                        value++;
                        break;
                    } else {
                        String arr[] = command.split(" ");
                        command = cmnds.get(Integer.parseInt(arr[2])-1);
                    }
                }
            }
            System.out.println(value);
        }
    }


}

12468 - Zapping

import java.util.Scanner;

class Another {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int from = scanner.nextInt();
            int to = scanner.nextInt();
            if (from == -1 && to == -1) break;

            int limit1, limit2;
            if (from < to) {
                limit1 = to - from;
                limit2 = 100 - limit1;
            } else {
                limit1 = from - to;
                limit2 = 100 - limit1;
            }

            if (limit1 < limit2) {
                System.out.println(limit1);
            } else {
                System.out.println(limit2);
            }
        }
    }


}

12157 - Tariff Plan

import java.util.Scanner;

class Another {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int testCases = scanner.nextInt();

        int counter = 0;
        while (testCases-- > 0) {

            counter++;
            int mild = 0, juice = 0;
            int n = scanner.nextInt();
            for (int i=0;i<n;i++) {
                int time = scanner.nextInt();
                mild += (time/30)+1;
                juice += (time/60) + 1;
            }

            mild = mild*10;
            juice = juice*15;

            if (mild < juice) {
                System.out.println("Case "+counter+": Mile "+mild);
            } else if (mild > juice) {
                System.out.println("Case "+counter+": Juice "+juice);
            } else {
                System.out.println("Case "+counter+": Mile Juice "+mild);
            }
        }
    }


}

12015 - Google is Feeling Lucky

import java.util.Scanner;

class Another {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int testCases = scanner.nextInt();

        scanner.nextLine();
        int counter = 0;
        while (testCases-- > 0) {

            counter++;
            System.out.println("Case #"+counter+":");
            int[] rating = new int[10];
            String[] urls = new String[10];

            int max = 0;
            for (int i=0;i<10;i++) {
                String line = scanner.nextLine();
                String[] arr = line.split(" ");
                urls[i] = arr[0];
                rating[i] = Integer.parseInt(arr[1]);
                if (rating[i] > max) {
                    max = rating[i];
                }

            }

            for (int i=0;i<10;i++) {
                if (rating[i] == max) {
                    System.out.println(urls[i]);
                }
            }
        }
    }


}

মঙ্গলবার, ১৩ জুন, ২০১৭

621 - Secret Research

import java.util.Scanner;

class Another {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int testCases = scanner.nextInt();
        scanner.nextLine();
        while (testCases-- > 0) {
            String input = scanner.nextLine();
            
            if (input.equals("1") || input.equals("4") || input.equals("78"))
                System.out.println("+");
            else if (input.endsWith("35"))
                System.out.println("-");
            else if (input.startsWith("9") && input.endsWith("4"))
                System.out.println("*");
            else if (input.startsWith("190"))
                System.out.println("?");
            else                System.out.println("?");
        }
    }


}

12577 - Hajj-e-Akbar

import java.util.Scanner;

class Another {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int counter = 0;
        while (scanner.hasNext()) {
            String input = scanner.nextLine();
            if (input.equals("*")) break;

            counter++;
            if (input.equals("Hajj")) {
                System.out.println("Case "+counter+": Hajj-e-Akbar");
            } else {
                System.out.println("Case "+counter+": Hajj-e-Asghar");
            }
        }
    }


}

12403 - Save Setu

import java.util.Scanner;

class Another {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int money = 0;
        int testCases = scanner.nextInt();
        scanner.nextLine();
        while (testCases-- > 0) {
            String operation = scanner.nextLine();
            if (operation.equals("report")) {
                System.out.println(money);
            } else {
                String arr[] = operation.split(" ");
                money += Integer.parseInt(arr[1]);
            }

        }
    }


}

12372 - Packing for Holiday

import java.util.Scanner;

class Another {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int counter = 0;
        int testCases = scanner.nextInt();
        while (testCases-- > 0) {
            counter++;

            int w = scanner.nextInt();
            int l = scanner.nextInt();
            int h = scanner.nextInt();

            if (w > 20 || l > 20 || h > 20) {
                System.out.println("Case "+counter+": bad");
            } else {
                System.out.println("Case "+counter+": good");
            }

        }
    }


}

12279 - Emoogle Balance

import java.util.Scanner;

class Another {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int counter = 0;
        while (scanner.hasNext()) {
            int n = scanner.nextInt();
            if (n == 0) break;
            counter++;
            int val = 0;
            while (n-- > 0) {
                if (scanner.nextInt() > 0) val++;
                else val--;
            }
            System.out.println("Case "+counter+": "+val);
        }
    }


}

12250 - Language Detection

import java.util.Scanner;

class Another {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int counter = 0;
        while (scanner.hasNext()) {
            String line = scanner.nextLine();
            if (line.equals("#")) break;
            counter++;

            switch (line) {
                case "HELLO":
                    System.out.println("Case "+counter+": ENGLISH");
                    break;
                case "HOLA":
                    System.out.println("Case "+counter+": SPANISH");
                    break;
                case "HALLO":
                    System.out.println("Case "+counter+": GERMAN");
                    break;
                case "BONJOUR":
                    System.out.println("Case "+counter+": FRENCH");
                    break;
                case "CIAO":
                    System.out.println("Case "+counter+": ITALIAN");
                    break;
                case "ZDRAVSTVUJTE":
                    System.out.println("Case "+counter+": RUSSIAN");
                    break;
                default:
                    System.out.println("Case "+counter+": UNKNOWN");
                    break;
            }
        }
    }


}

11364 - Parking

import java.util.Arrays;
import java.util.Scanner;

class Another {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int testCases = scanner.nextInt();
        while (testCases-- > 0) {
            int shops = scanner.nextInt();
            int[] nums = new int[shops];
            for (int i=0;i<shops;i++) {
                nums[i] = scanner.nextInt();
            }
            Arrays.sort(nums);
            int dist = 0;
            for (int i=0;i<nums.length-1;i++) {
                dist += (nums[i+1]-nums[i]);
            }

            System.out.println(dist*2);
        }
    }


}

11044 - Searching for Nessy

import java.util.Scanner;

class Another {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int testCases = scanner.nextInt();
        while (testCases-- > 0) {
            int x = scanner.nextInt();
            int y = scanner.nextInt();

            System.out.println((x/3)*(y/3));
        }
    }


}

10550 - Combination Lock

import java.util.Scanner;

class Another {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int start = scanner.nextInt();
            int first = scanner.nextInt();
            int second = scanner.nextInt();
            int third = scanner.nextInt();

            if (start == 0 && first == 0 && second == 0 && third == 0) break;

            System.out.println(1080 + ((start - first + 40) % 40 + (second - first + 40) % 40 + (second - third + 40) % 40) * 9);
        }
    }


}

12289 - One-Two-Three

import java.util.Scanner;

class Another {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int cases = scanner.nextInt();
        while (cases-- >= 0) {
            String input = scanner.nextLine();

            switch (input.length()) {
                case 3:
                    int two = 0, one = 0, six = 0, ten = 0;

                    if (input.charAt(0) == 'o') one++;
                    else if (input.charAt(0) == 't') {
                        two++;
                        ten++;
                    } else if (input.charAt(0) == 's') six++;

                    if (input.charAt(1) == 'n') one++;
                    else if (input.charAt(1) == 'w') two++;
                    else if (input.charAt(1) == 'i') six++;
                    else if (input.charAt(1) == 'e') ten++;

                    if (input.charAt(2) == 'e') one++;
                    else if (input.charAt(2) == 'o') two++;
                    else if (input.charAt(2) == 'x') six++;
                    else if (input.charAt(2) == 'n') ten++;

                    if (one == 2 || one == 3) System.out.println(1);
                    else if (two == 2 || two == 3) System.out.println(2);
                    else if (six == 2 || six == 3) System.out.println(6);
                    else if (ten == 2 || ten == 3) System.out.println(8);

                    break;
                case 5:
                    int three = 0, seven = 0, eight = 0;
                    if (input.charAt(0) == 't') three++;
                    else if (input.charAt(0) == 's') seven++;
                    else if (input.charAt(0) == 'e') eight++;

                    if (input.charAt(1) == 'h') three++;
                    else if (input.charAt(1) == 'e') seven++;
                    else if (input.charAt(1) == 'i') eight++;

                    if (input.charAt(2) == 'r') three++;
                    else if (input.charAt(2) == 'v') seven++;
                    else if (input.charAt(2) == 'g') eight++;

                    if (input.charAt(3) == 'e') {
                        three++;
                        seven++;
                    }
                    else if (input.charAt(3) == 'h') eight++;

                    if (input.charAt(4) == 'e') three++;
                    else if (input.charAt(4) == 'n') seven++;
                    else if (input.charAt(4) == 't') eight++;

                    if (three == 4 || three == 5) System.out.println(3);
                    else if (seven == 4 || seven == 5) System.out.println(7);
                    else if (eight == 4 || eight == 5) System.out.println(8);
                    break;
                case 4:
                    int four = 0, five = 0, nine = 0;

                    if (input.charAt(0) == 'f'){
                        four++;
                        five++;
                    }
                    else if (input.charAt(0) == 'n') nine++;

                    if (input.charAt(1) == 'o') four++;
                    else if (input.charAt(1) == 'i') {
                        five++;
                        nine++;
                    }


                    if (input.charAt(2) == 'u') four++;
                    else if (input.charAt(2) == 'v') five++;
                    else if (input.charAt(2) == 'n') nine++;

                    if (input.charAt(3) == 'r') four++;
                    else if (input.charAt(3) == 'e') {
                        five++;
                        nine++;
                    }

                    if (four == 3 || four == 4) System.out.println(4);
                    else if (five == 3 || five == 4) System.out.println(5);
                    else if (nine == 3 || nine == 4) System.out.println(9);


                    break;
            }
        }
    }


}

রবিবার, ১১ জুন, ২০১৭

686 - Goldbach's Conjecture (II)

import java.util.*;

public class Main2 {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        boolean[] primeList = new boolean[33000];
        primeList[2] = true;
        primeList[3] = true;
        for (int i=4;i<33000;i++) {
            primeList[i] = isPrime(i);
        }
        while (scanner.hasNextInt()) {
            int num = scanner.nextInt();
            if (num == 0) break;
            int counter = 0;
            for (int i=2;i<=num/2;i++) {
                if (primeList[i] && primeList[num-i]) counter++;
            }

            System.out.println(counter);
        }
    }

    static boolean isPrime(int num) {
        for (int i=2;i<=num/2;i++) {
            if (num%i == 0) return false;
        }
        return true;
    }
}