In: Computer Science
Right now Lili is in a strange planet and she wants to study the calendar system of said planet. Each year on the planet consists of N months and each month on the planet consists of exactly K days. Bibi arrived on the planet on the first day of the first month, and now she has T questions: What’s the month and date on Bibi’s A i-th day on the planet? Help her to answer the questions!
Format Input
The first line contains the numbers N and K. The next N lines contain Si which is the name of the i-th month. The next line then contains T and next T lines contain A i.
Format Output
For each question, output one line starting with “Case # X: ” (without quotes) where X is the question number (starting from 1) followed by the month and date on Bibi’s A i-th day on the planet.
Constraints
• 1 ≤ N, K ≤ 100
• 1 ≤ Q ≤ 1000
• 1 ≤ A i ≤ 1000000
• 1 ≤ | Si | ≤ 100 (|Si| means the length of Si )
• Si only contains lowercase English letters a-z
Sample Input 1 (standard input)
12 30
january
february
march
april
may
june
july
august
september
october
november
december
10
1
2
31
69
360
361
362
420
720
1337
Sample Output 1 (standard output)
Case #1: january 1
Case #2: january 2
Case #3: february 1
Case #4: march 9
Case #5: december 30
Case #6: january 1
Case #7: january 2
Case #8: february 30
Case #9: december 30
Case #10: september 17
NOTE: USE C LANGUAGE, DONT USE FUNCTION(RESULT,RETURN),VOID,RECURSIVE, USE BASIC CODE AND CODE IT UNDER int main (){, constraint must be the same
Here our task is to make a program which find out month and date for specific duration of days
Points to remember while coding
CODE
(please read all comments for better undersatanding of the program)
SAMPLE RUN
Text version of the code to copy paste
#include <stdio.h>
int main() //main function starts here
{
int N,K,Q; //declaring variables
scanf("%d %d", &N, &K); //recieving no of month and no of
day in a month
char Si[N][100]; //2 D array to store names of months
for(int i=0;i<N;i++){ //getting all months from user
scanf("%s",&Si[i]);
}
scanf("%d", &Q); //recieving value for Q
int Ai[1000];
int month,days,day;
for (int j=0;j<Q;j++){ //reciving user input for no of days in
array 'Ai[]'
scanf("%d",&Ai[j]);
}
for (int m=0;m<Q;m++){
days=Ai[m]%(N*K); //calculating days passed after beginning of last
yer
month=days/K; //calculating no of months
day=days%K; //calculating date of month
if(day==0){ //there is no 0th day in a month so if a day become '0'
make it K
day=K;
if(month==0){
month=N-1; //if day is '0' and month is 0 then it will be Nth of
last month
}
else{
month=month-1;
}
}
printf("case #%d:",m+1); //printing in order specified in
question
printf(" %s", Si[month]);
printf(" %d \n", day);
}
return 0;
}