Question

In: Computer Science

Right now Lili is in a strange planet and she wants to study the calendar system...

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

Solutions

Expert Solution

Here our task is to make a program which find out month and date for specific duration of days

Points to remember while coding

  • We need to declare a varible to store no of month (N) and Days in a month(K)
  • Name of each month can be stored in a 2D array
  • Store inputs such as name of months and duration(Ai) with help of loops
  • days passed after beginning of last year can be calculated by days=duration (in days)%(no of months in a year*days in a month);
  • month can be calcculated by ,month=days /No of months
  • i th day=days%No of days in a month
  • We also have to take care of cases when i th day become 0.in such cases i th day should be last day previous month

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;
}


Related Solutions

Your aunt has $780,000 invested at 5.5%, and she now wants to retire. She wants to...
Your aunt has $780,000 invested at 5.5%, and she now wants to retire. She wants to withdraw $45,000 at the beginning of each year, beginning immediately. She also wants to have $50,000 left to give you when she ceases to withdraw funds from the account. For how many years can she make the $45,000 withdrawals and still have $50,000 left in the end?
A student states that sulfates are bad for our planet because they warm the planet. Now...
A student states that sulfates are bad for our planet because they warm the planet. Now that you have a much greater understanding of the chemistry of various molecules, please help enlighten this student.
Glenn is selling food in restaurant. She is using POS system. So if she wants to...
Glenn is selling food in restaurant. She is using POS system. So if she wants to store the food sets in array, how to use search function to search the food sets from the array by using(( JAVA )) and display it ? I want a sample like this, thank you For example: Enter the set you want to search: SET1 SET1 $10 Cheese Burger Coke fries --------------------------------------------------------- Your Entire food menu : SET1 $10 Cheese Burger Coke fries SET2...
Ayasha, age 30, is beginning to contemplate her financial future. Right now, she lives in a...
Ayasha, age 30, is beginning to contemplate her financial future. Right now, she lives in a large city where she rents a one-bedroom apartment. Although she loves the excitement of the city, she knows that someday she would like to move to the country and live in a farmhouse. Her goal is to begin saving for this objective right away. Ayasha has identified three possible portfolios that might be appropriate choices as she begins investing to reach her objective. Each...
Now that Hermione understands empirical formulas she wants to teach Harry and Ron. What is the...
Now that Hermione understands empirical formulas she wants to teach Harry and Ron. What is the empirical formula for dibromoethane: C2H4Br2 A. CH2Br2 B. CH2Br C. C2H4Br D. CHBr E. C2H2Br2 2.Calculate the maass percent composition of carbon in C​​2​H​5Cl.​
Planning for the Future Ayasha, age 30, is beginning to contemplate her financial future.  Right now, she...
Planning for the Future Ayasha, age 30, is beginning to contemplate her financial future.  Right now, she lives in a large city where she rents a one-bedroom apartment. Although she loves the excitement of the city, she knows that someday she would like to move to the country and live in a farmhouse. Her goal is to begin saving for this objective right away.  Ayasha has indentified three possible portfolios that might be appropriate choices as she begins investing to reach her...
4. Ms. Laila is examining the cellular organelles in the slide and she wants to study...
4. Ms. Laila is examining the cellular organelles in the slide and she wants to study about the ribosomes. Answer the following based on Laila’s requirement. (2.5 Marks) a) What type of microscope is used to view these organelles? b) Explain principle and working mechanism of the microscope which doesn’t penetrate the organelles but measures the size and structure.
Rita is the owner of Rita’s Osteria. She wants to study the growth of her business...
Rita is the owner of Rita’s Osteria. She wants to study the growth of her business using simulation. She is interested in simulating the number of customers and the amount ordered by customers each month. She feels that the number of customers is normally distributed, with a mean of 800 and a standard deviation of 45. The bill for each customer is $65 and uniformly distributed, with a maximum increase of 8% and a minimum decrease of 5%. The changes...
Your sister will start college exactly 1 year from now and she wants to join you...
Your sister will start college exactly 1 year from now and she wants to join you at Marquette University. Marquette University offers a couple of payment plans for the tuition fee. Flexible Plan: Pay once a year but the tuition will increase at 5% per year (which is much lower than other schools). The first payment due at the very first day of school. This year, the tuition is $30,000. Convenient Plan: Lock in by paying a lump sum of...
Lisa Simpson, now age 20, wants to retire with $1,500,000 in her Roth IRA. She plans...
Lisa Simpson, now age 20, wants to retire with $1,500,000 in her Roth IRA. She plans to achieve this goal by depositing $3,000 at the beginning of each year at an expected annual rate of 8%. How many deposits must Lisa make in order to reach her goal? Round to the nearest deposit.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT