Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // let input = [
- // '7 March 2021', // the input is always a string, so it's '3' and not 3
- // '30',
- // '30',
- // '7'
- // ];
- let input = [
- '11 March 2021', // the input is always a string, so it's '3' and not 3
- '22',
- '27',
- '35'
- ];
- let print = this.print || console.log;
- let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
- // Input
- let expectedDate = gets().split(' ');
- let day = +expectedDate[0];
- let month = expectedDate[1];
- let year = +expectedDate[2];
- let averageTemperature = +gets();
- let optimalAverageTemperature = 20;
- let rain = +gets();
- let optimalRain = 30;
- let winterLength = +gets();
- // Solution
- let itsLeapYear = (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
- if (itsLeapYear) averageTemperature += 5;
- day += Math.floor(winterLength / 7);
- day -= averageTemperature - optimalAverageTemperature;
- day += Math.floor(Math.abs(rain - optimalRain) / 3)
- if (day > 31) {
- day -= 31;
- month = "April";
- }
- if (day < 0) {
- day += 28;
- month = "February";
- if (itsLeapYear) day += 1;
- }
- // Output
- console.log(`${day} ${month} ${year}`);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement