×

# EVENT Editorial

Primary Tester: Amir Reza PoorAkhavan
Editorialist: Hussain Kara Fallah

Cakewalk

None

# PROBLEM:

Given the name of the day that some contest started at (Saturday, Sunday, Monday....), and the name of the day it was finished. You have to tell if the duration of the contest is some integer in the range [L, R].

If there's no such number in the range output "none".

If there's one number in the range output this number.

If there's more than one possible number in the range output "many".

# EXPLANATION:

The minimum possible duration of the contest is the difference in days between the name of the first day and the name of the second. Start with the day of start, and keep counting till you reach the other day. Let's name this value D.

Now, what are the possible other values?

Clearly, It's D + 7 * K, where K is an arbitrary non-negative integer (which means that it lasts for K extra full weeks). So we need to check how many values K makes our value D in the range [L,R]. This can be done with simple calculations, or maybe a loop since constraints are small.

# Example:

Consider our sample was "Saturday Sunday 2 4".

The minimum possible duration of the contest is 2.

Other possible values {9,16,23,30,...etc}.

Only 2 belongs to the interval thus the answer is 2.

# AUTHOR'S AND TESTER'S SOLUTIONS:

AUTHOR's solution

Editorialist's solution

This question is marked "community wiki".

1181234
accept rate: 0%

19.8k350498541

 0 PLEASE FIND THE BUG WOEKING FINE IN MY LOCAL MACHINE import java.util.; import java.lang.; import java.io.*; / Name of the class has to be "Main" only if the class is public. / class Codechef { private static Scanner mScanner=new Scanner(System.in); private static final String IMPOSSIBLE="impossible"; private static final String MANY="many"; public static void main (String[] args) throws java.lang.Exception { try { int noTestCases=Integer.parseInt(mScanner.nextLine()); while(noTestCases-->0) { String weekDays=mScanner.nextLine(); int lowestExpectedDay=Integer.parseInt(mScanner.nextLine()); int highestExpectedDay=Integer.parseInt(mScanner.nextLine()); String weekDaysArrys[]=weekDays.split(" "); int minimumCompetionDays=getMinimumCompetionDays(weekDaysArrys); if(minimumCompetionDays>highestExpectedDay) System.out.println(IMPOSSIBLE); else if((highestExpectedDay-lowestExpectedDay)+1>13) System.out.println(MANY); else{ int estimatedDay=minimumCompetionDays; while(lowestExpectedDay>estimatedDay) { estimatedDay=estimatedDay+7; } if(estimatedDay>highestExpectedDay) System.out.println(IMPOSSIBLE); else System.out.println(String.valueOf(estimatedDay)); } } } catch(Exception e) { } // your code goes here } private static int getMinimumCompetionDays(String[] weekDays){ String startWeekDay=weekDays[0]; String endWeekDay=weekDays[1]; int startWeekDayNo=getWeekDaysInNumber(startWeekDay.toLowerCase()); int endWeekDayNo=getWeekDaysInNumber(endWeekDay.toLowerCase()); if(startWeekDayNo==endWeekDayNo) return 1; else return (endWeekDayNo-startWeekDayNo)+1; } private static int getWeekDaysInNumber(String weekDayString){ switch(weekDayString) { case "monday": return 1; case "tuesday": return 2; case "wednesday": return 3; case "thursday": return 4; case "friday": return 5; case "saturday": return 6; case "sunday": return 7; } return 1; }  } answered 31 Jan, 00:20 0★drdang 1●1 accept rate: 0%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×1,688
×850
×56

question asked: 24 Nov '18, 23:56

question was seen: 1,657 times

last updated: 31 Jan, 00:20