We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Tutorials
  3. 30 Days of Code
  4. Day 26: Nested Logic
  5. Discussions

Day 26: Nested Logic

Problem
Submissions
Leaderboard
Discussions
Editorial
Tutorial

Sort 737 Discussions, By:

recency

Please Login in order to post a comment

  • allan34291
    2 weeks ago+ 0 comments

    Here's my solution in Java:

    import java.util.Scanner;
    
    public class Solution {
    
        public static int calculateFine(int[] actualReturnDateIntegerArray, int[] expectedReturnDateIntegerArray) {
            // Date format: day, month, year
            int fine = 0;
            
            if (actualReturnDateIntegerArray[2] < expectedReturnDateIntegerArray[2])
                return fine;
            else if (actualReturnDateIntegerArray[2] == expectedReturnDateIntegerArray[2]) {
                if (actualReturnDateIntegerArray[1] < expectedReturnDateIntegerArray[1]) {
                    return fine;
                } else if (actualReturnDateIntegerArray[1] == expectedReturnDateIntegerArray[1]) {
                    if (actualReturnDateIntegerArray[0] <= expectedReturnDateIntegerArray[0]) {
                        return fine;
                    } else {
                        fine = 15 * (actualReturnDateIntegerArray[0] - expectedReturnDateIntegerArray[0]);
                        return fine;
                    }
                } else {
                    fine = 500 * (actualReturnDateIntegerArray[1] - expectedReturnDateIntegerArray[1]);
                    return fine;
                }
            } else if (actualReturnDateIntegerArray[2] > expectedReturnDateIntegerArray[2]) {
                fine = 10000;
                return fine;
            }
            return fine;
        }
        
        public static void main(String[] args) {
            /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
            Scanner scanner = new Scanner(System.in);
            String actualReturnDate = scanner.nextLine();
            String expectedReturnDate = scanner.nextLine();
            
            String[] actualReturnDateStringArray = actualReturnDate.split(" ");
            String[] expectedReturnDateStringArray = expectedReturnDate.split(" ");
            
            int[] actualReturnDateIntegerArray = new int[actualReturnDateStringArray.length];
            int[] expectedReturnDateIntegerArray = new int[expectedReturnDateStringArray.length];
            
            for (int index = 0; index < actualReturnDateStringArray.length; index++) {
                actualReturnDateIntegerArray[index] = Integer.parseInt(actualReturnDateStringArray[index]);
                expectedReturnDateIntegerArray[index] = Integer.parseInt(expectedReturnDateStringArray[index]);
            }
            
            int fine = calculateFine(actualReturnDateIntegerArray, expectedReturnDateIntegerArray);
            
            System.out.println(fine);
        }
    }
    
    0|
    Permalink
  • jesseabuaja1
    3 weeks ago+ 0 comments

    My JavaScript solution;

    function processData(input) {
        //Enter your code here
        const [returnDate, dueDate] = input.split("\n").map(d => d.split(" ").map(s => parseInt(s)))
        if((returnDate[0] <= dueDate[0] && returnDate[1] <= dueDate[1] && returnDate[2] <= dueDate[2]) || returnDate[2] < dueDate[2]) {
            return console.log(0)
        }
        if(returnDate[0] > dueDate[0] && returnDate[1] === dueDate[1] && returnDate[2] <= dueDate[2]) {
            return console.log(15 * (returnDate[0] - dueDate[0]))
        }
        if(returnDate[1] > dueDate[1] && returnDate[2] === dueDate[2]) {
            return console.log(500 * (returnDate[1] - dueDate[1]))
        }
        if(returnDate[2] > dueDate[2]) {
            return console.log(10000)
        }
    } 
    
    0|
    Permalink
  • roshankumar350
    3 weeks ago+ 0 comments

    swift Solution

    let returnedDate = readLine()!.components(separatedBy: .whitespaces)
    let dueDate = readLine()!.components(separatedBy: .whitespaces)
    
    let dueDateComponent: (day: String, month: String, year: String) = (dueDate[0], dueDate[1], dueDate[2])
    
    let returnedComponent: (day: String, month: String, year: String) = (returnedDate[0], returnedDate[1], returnedDate[2])
    
    let dueDateYear = Int(dueDateComponent.year) ?? Int.min
    let returnedYear = Int(returnedComponent.year) ?? Int.min
    
    let dueDateMonth = Int(dueDateComponent.month) ?? Int.min
    let returnedMonth = Int(returnedComponent.month) ?? Int.min
    
    let dueDateDay = Int(dueDateComponent.day) ?? Int.min
    let returnedDay = Int(returnedComponent.day) ?? Int.min
    
    func calculateFine() {
        guard returnedYear >= dueDateYear else {
            print(0)
            return
        }
        
        guard returnedYear == dueDateYear else {
            print(10000)
            return
        }
        
        guard returnedMonth <= dueDateMonth else {
            let diff = returnedMonth - dueDateMonth
            print(diff*500)
            return
        }
        
        guard returnedDay <= dueDateDay else {
            let diff = returnedDay - dueDateDay
            print(diff*15)
            return
        }
        
        print(0)
    }
    
    calculateFine()
    
    0|
    Permalink
  • teymurnasir
    4 weeks ago+ 0 comments

    JavaScript Solution

    function processData(input) {
        //Enter your code here
        
        
        var date_returned = input.split("\n")[0].split(" ")
        var date_due = input.split("\n")[1].split(" ")
        
        calculateFee(date_returned.map(Number),date_due.map(Number));
    
    } 
    
    function calculateFee(date_returned,date_due){
        
        var hackos= 0; 
        
        if(date_returned[2]>date_due[2]){
            hackos= 10000;
        }else if(date_returned[1]>date_due[1] && date_returned[2]===date_due[2]){
            hackos= 500*(date_returned[1]-date_due[1]);
        }else if(date_returned[0] > date_due[0] && date_returned[1]===date_due[1] && date_returned[2]===date_due[2]){
            hackos = 15*(date_returned[0]-date_due[0]);
        }
        
        console.log(hackos);
    }
    
    0|
    Permalink
  • e_ozbey01
    4 weeks ago+ 0 comments

    My Soluton for Java;

    public static void main(String[] args) {

        Scanner in= new Scanner(System.in);
        int[] arr= new int[6];
        for(int i=0; i<6;i++)
        {
            arr[i]= in.nextInt();
        }
        int fine=0;
        int actualrday=arr[0];
        int actualrmonth=arr[1];
        int actualryear=arr[2];
        int expectedrday=arr[3];
        int expectedrmonth=arr[4];
        int expectedyear=arr[5];
        in.close();
    
    
        if(actualryear==expectedyear)
        {
            if(actualrmonth<=expectedrmonth){
                if(actualrday<=expectedrday)
                {
                    fine=0;
                }
                else{fine=(actualrday-expectedrday)*15;}
            }
            else{fine=(actualrmonth-expectedrmonth)*500;}    
        }
        else if(actualryear<expectedyear)
        {
            fine=0;
        }
        else if(actualryear>expectedyear){fine=10000;}
    
        System.out.println(fine);
    }
    
    0|
    Permalink
Load more conversations

Need Help?


View tutorial
View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy