Sort by

recency

|

788 Discussions

|

  • + 0 comments

    rd,rm,ry=map(int,input().split()) dd,dm,dy=map(int,input().split()) t=0 if ry>dy: t+=10000 elif ry==dy: if rm>dm: t+=((rm-dm)*500) elif rm==dm: if rd>dd: t+=((rd-dd)*15) print(t)

  • + 0 comments

    JavaScript Solution:

    `{month.padStart(2, "0")}-${day.padStart(2, "0")}; }

    function calculateFine(dateReturned, dateDue) { const returnedDate = new Date(dateReturned); const dueDate = new Date(dateDue);

    // Compare years const yearsLate = returnedDate.getFullYear() - dueDate.getFullYear(); if (yearsLate > 0) return 10000; if (yearsLate < 0) return 0;

    // Compare months (only if same year) const monthsLate = returnedDate.getMonth() - dueDate.getMonth(); if (monthsLate > 0) return monthsLate * 500; if (monthsLate < 0) return 0;

    // Compare days (only if same year and same month) const daysLate = returnedDate.getDate() - dueDate.getDate(); if (daysLate > 0) return daysLate * 15;

    return 0; }

    function processData(input) { const [returned, due] = input.split("\n"); const dateReturned = formatDateString(returned); const dateDue = formatDateString(due);

    console.log(calculateFine(dateReturned, dateDue)); }

  • + 0 comments

    Pure C:

    #include <stdio.h>
    #include <string.h>
    #include <math.h>
    #include <stdlib.h>
    
    
    //----------------------------------------------------------------------------------------------
    
    /*!
     * @brief given a date in yyyymmdd format, returns the number of days elapsed since 01-01-01 CE
     * @note assumes gregorian, no error checking is done since valid dates guaranteed by problem statement
     */
    unsigned long days_since_bce(int num_years, int num_months, int num_days)
    {
        unsigned long accum    =    0;
        
        //------------- year handling ---------------------------------------
        // days in normal years
        accum += num_years * 365;
        
        // days in leap years
        accum += (num_years / 4) - (num_years / 100) + (num_years / 400);
        
        //------------- month handling --------------------------------------
        // add the number of days of the _previous_ months
        // fallthroughs are intentional
        switch (num_months)
        {
            case 12:    accum += 30; 
            case 11:    accum += 31; 
            case 10:    accum += 30; 
            case 9:     accum += 31; 
            case 8:     accum += 31; 
            case 7:     accum += 30; 
            case 6:     accum += 31; 
            case 5:     accum += 30; 
            case 4:     accum += 31; 
            case 3:     accum += 28; 
            case 2:     accum += 31; 
        }
        
        //------------- day handling --------------------------------------
        accum += num_days;
        
        //------------- done ----------------------------------------------
        return accum;
    }
    
    
    //----------------------------------------------------------------------------------------------
    
    int main() {
        int y_returned;
        int m_returned;
        int d_returned;
    
        scanf("%d %d %d", &d_returned, &m_returned, &y_returned);
        unsigned long return_date = days_since_bce(y_returned, m_returned, d_returned);
    
        int y_due;
        int m_due;
        int d_due;
    
        scanf("%d %d %d", &d_due, &m_due, &y_due);
        unsigned long due_date = days_since_bce(y_due, m_due, d_due);
        
        long fine = (return_date - due_date)*15L;
        
        // returned early ?
        if (fine < 0) fine = 0;
        
        // returned after a year boundary ?
        if (y_returned > y_due) fine = 10000;
        
        // returned after a month boundary ?
        if (y_returned == y_due)
        {
            if (m_returned > m_due) fine = (500 * (m_returned - m_due));
        }
        
        // all done
        printf("%ld", fine );
    
        return 0;
    }
    
  • + 0 comments

    JavaScript

    function formatDateString(gregorianDate) {
        const date = gregorianDate.split(" ");
        const day = date[0].padStart(2, "0");
        const month = date[1].padStart(2, "0");
        const year = date[2].padStart(4, "0");
        return `${year}-${month}-${day}`;
    }
    
    function calculateFine(dateReturned, dateDue) {
        const returnedDate = new Date(dateReturned);
        const dueDate = new Date(dateDue);
        const distanceInDays = (returnedDate - dueDate) / (1000 * 60 * 60 * 24);
    
        if (distanceInDays <= 0) return 0;
        
        const chargePerDay = 15;
        const chargePerMonth = 500;
        const chargePerYear = 10000;
        
        const daysLate = returnedDate.getDate()  - dueDate.getDate();
        const monthsLate = returnedDate.getMonth() - dueDate.getMonth();
        const yearsLate = returnedDate.getFullYear() - dueDate.getFullYear();
    
        if (yearsLate > 0) {
            return chargePerYear;
        }
        
        if (monthsLate > 0) {
            return monthsLate * chargePerMonth;
        }
        
        if(daysLate > 0) {
            return daysLate * chargePerDay;
        }
    }
    
    function processData(input) {
        var input_stdin_array = input.split("\n");
        const dateReturned = formatDateString(input_stdin_array[0]);
        const dateDue = formatDateString(input_stdin_array[1]);
       
        console.log(calculateFine(dateReturned, dateDue));
    }
    
  • + 0 comments

    javaScript` solution

    function processData(input) { const inputArr = input.split('\n'); const actual = inputArr[0].split(' ').map(Number); // Convert to numbers const expected = inputArr[1].split(' ').map(Number); // Convert to numbers const day = 0; const month = 1; const year = 2;

    let fine = 0;

    if (actual[year] > expected[year]) { fine = 10000; } else if (actual[year] === expected[year] && actual[month] > expected[month]) { fine = 500 * (actual[month] - expected[month]); } else if (actual[year] === expected[year] && actual[month] === expected[month] && actual[day] > expected[day]) { fine = 15 * (actual[day] - expected[day]); }

    console.log(fine); } `