Académique Documents
Professionnel Documents
Culture Documents
Lets suppose we have a clock that has an hour hand 3 units long, a minute hand 4
units long, and a second hand 5 units long. The hour hand moves once every hour,
the minute hand moves once every minute, and the second hand moves once every
second. Therefore, exactly every second, the triangle defined by the ends of the
hands changes its area.
Output: The maximum area defined by the ends of the hands in square units.
My code:
I have written a function that takes as arguments the position of the hands in
radians and returns its area (trigonometrically intensive).
double s = (distSM+distSH+distMH)/2;
return s*(s-distSM)*(s-distSH)*(s-distMH);
}
My main function reads the input from the user and calculates the area for each
second in the range of time the user has entered, stores the maximum area and
finally prints it.
int main(){
char z;
double hI,mI,sI, hF,mF,sF;
while(cin >> hI >> z >> mI >> z >> sI >> hF >> z >> mF >> z >> sF){
double maxArea = 0;
for(int i = 3600*hI+60*mI+sI; i <= 3600*hF+60*mF+sF; i++){
double cacheArea = area( 2*pi*((double)(i%60)/60) , 2*pi*(double)((i
%3600)/60)/60, 2*pi*(double)((i%43200)/3600)/12);
if(cacheArea > maxArea) maxArea = cacheArea;
}
cout << fixed << setprecision(3) << sqrt(maxArea) << endl;
}
}