পৃষ্ঠাসমূহ

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

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);
        }

    }

}