[URI ONLINE JUDGE] – 1893 – Moon Phases

Link: https://www.urionlinejudge.com.br/judge/en/problems/view/1893

Jade won as birthday gift a telescope and is very happy, because she loves stay looking the moon at night. She was always a very good student, and just analyzing the moon for two consecutive nights, she can already identify the changes that occurred in lighting and the approximate percentage of the moon that are illuminated.

You, who is a Jade’s friend and a Computer Science student, decided to make a small program that, based on her analise made in the last two nights, informs the phase in which the moon is. If the visible portion of the moon is between 0 and 2%, for example, is new moon (“nova” in portuguese). If it is between 3 and 96% is crescent moon (“crescente” in portuguese), if it is between 97 and 100% is full moon (“cheia” in portuguese) and it is between 3 and 96 % (decreasing) is waning moon (“minguante” in portuguese).

Input

The input consists of a single line containing two integer numbers. The first number corresponds to the percentage observed by Jade at night two days ago. The second value corresponds to the percentage observed by jade the night before.

Output

Based on the two percentage observed by Jade, print on the screen at what stage the moon was in the night before. Don’t forget the end-of-line character :)

Input Sample Output Sample
0 2 nova
2 3 crescente
99 97 cheia
97 94 minguante
30 35 crescente

solution:

 

<br />#include <iostream>
using namespace std;

bool solve(int num) {
return num >= 0 && num <= 2;
}

bool crescent(int num){
return num >= 3 && num <= 96;
}
bool full_moon(int num) {
return num >= 97 && num <= 100;
}

int main()
{
int first,second;
cin>> first >>second;

if(first <= second)
{
if(solve(second))
cout << "nova" << endl;
else if(crescent(second))
cout << "crescente" <<endl;
else if (full_moon(second))
cout << "cheia" <<endl;
}
else
{
if(solve(second))
cout << "nova" << endl;
else if(crescent(second))
cout << "minguante" <<endl;
else if (full_moon(second))
cout << "cheia" <<endl;
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s