Wednesday 6 July 2016

Hackerrank , 30 Days of Code Challenges ( Day 26th & 27th Solution)

 Day 26: Nested Logic :
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

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

        int actualDay = sc.nextInt();
        int actualMonth = sc.nextInt();
        int actualYear = sc.nextInt();
        int expectedDay = sc.nextInt();
        int expectedMonth = sc.nextInt();
        int expectedYear = sc.nextInt();

        int fine;
        if (actualYear > expectedYear) {
            fine = 10000;
        } else if (actualMonth > expectedMonth && (actualYear >= expectedYear)) {
            fine = 500 * (actualMonth - expectedMonth);
        } else if (actualDay > expectedDay && (actualMonth >= expectedMonth) && (actualYear >= expectedYear)) {
            fine = 15 * (actualDay - expectedDay);
        } else {
            fine = 0;
        }
        System.out.println(fine);

        sc.close();
    }
}

Day 27: Testing :

print "5"
print "4 3"
print "-1 0 4 2"
print "5 3"
print "0 1 -2 -6 9"
print "6 4"
print "1 0 -3 4 5 7"
print "7 5"
print "0 -3 -2 -1 6 -8 9"
print "8 6"
print "2 -4 5 1 3 7 6 0"

No comments:

Post a Comment