Computer Science, asked by jaswanthrocks842, 9 months ago

There are 360 Longitudes on the Earth, which are equidistant vertical imaginary lines drawn on the Earth, separated by 1 degree each from center of the Earth. Period of the rotation of the Earth on its axis is 24 hours. All countries have their own official times and hence time zones.
UTC is universal time coordinate which passes through 0 (Zero degree) longitude.
Time at a particular location on Earth can be calculated using period of the rotation of Earth and longitude of that particular location. For example, Indian time zone IST (Indian standard Time) is located at 82.5° E longitude. Hence, Indian time can be calculated as below:-
IST = UTC + (24/360)*82.5 = UTC + 5:30Hrs
Now suppose we changed period of rotation of the earth using some imaginary power, this will change the time at every longitude on the earth.
Calculate the smallest angle between hour and minute hand of the clock , which shows the difference of time at a particular longitude and the time at UTC i.e. we have to take smaller of the two angle formed between hour and minute hand.
com.tcs.cv.automata.ei.middleware.DocxToHtmlConverter@133decd2:image1.jpeg
Constraints
To show the time difference on clock, 12-hour clock (as shown below) shall be used, irrespective of period of the earth's rotation, for this question only.
Input Format
1. Period of the earth’s rotation in Hours (Integer only)
2. Value of Longitude up to 2 place of decimal
Output
Smallest angle between hour and minute hand of the clock, which shows the difference between time at a particular longitude and time at UTC, up to 2 decimal places.
Test Case


Explanation
Example 1
Input
24
82.50
Output
15.00
Explanation
If period of rotation of earth is 24 hours then time at 82.5 degree longitude will be (24/360)*82.50 = 5:30 and minimum angle at this time between minute and hour hand will be 15 degree.
Example 2
Input
12
360.00
Output
0.00
Explanation
If period of rotation of earth is 12 hours then time at 360 degree longitude will be (12/360)*360 = 12:00 and minimum angle at this time between minute and hour hand will be 0 degree.

Answers

Answered by GulabLachman
0

Program:

#include<iostream>

#include<cstdlib>

using namespace std;  

int min(int x, int y)  

{  

   return (x < y)? x: y;        

}  

int anglediff (int hour, float minute)

{

//hour = 24  minute = 82.50

float time;

float hourf= (float)hour;

time= ((float)(hourf/360))*minute;//int/int it gave zero.

int htime=(int) (time); //5

float l=(float)time-htime;//0.50

float k= l*0.6; // 0.30

int mtime= k*100; //30

if(htime==12)

htime=0;

if(mtime==60)

mtime=0;

int hour_angle = 0.5 * (htime * 60 + mtime);

   int minute_angle = 6 * mtime;  

 int angle = abs(hour_angle - minute_angle);    

   angle = min(360 - angle, angle);  

   return angle;  

}

int main(void)

{

int PerOfEartRota;

float longi;

scanf("%d",&PerOfEartRota);

scanf("%f",&longi);

float angle;

angle = anglediff(PerOfEartRota, longi);

printf("%.2f", angle);

return 0;

}

 

NOTE:

  • 12hr = 360  therefore, 1hr = 360/12 = 30
  • 60min = 360  therefore, 1min = 360/60 = 6
  • The minute hand moves 360 degrees in 60 minutes (or 6 degrees in one minute) and, the hour hand moves 360 degrees in 12 hours(or 0.5 degrees in 1 minute).
  • In h hours and m minutes, the minute hand would pass = (h*60 + m)*6, and the hour hand would pass = (h*60 + m)*0.5.
Similar questions