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.
Day 26: Nested Logic
Day 26: Nested Logic
Sort by
recency
|
788 Discussions
|
Please Login in order to post a comment
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)
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)); }
Pure C:
JavaScript
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); } `