Algorithm


Problem Name: 2 AD-HOC - beecrowd | 1893

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

Moon Phases

 

By Neilor Tonin, URI BR Brazil

Timelimit: 1

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

 

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include <stdio.h>

#define true 1
#define false 0

int main (int argc, char **argv)
{

	int n, m;
	scanf("%d %d", &n, &m);

	if (n > m || n == m)
	{

		if (m >= 97)
			printf("cheia\n");
		else if (m  < = 96 && m >= 3)
			printf("minguante\n");
		else
			printf("nova\n");

	}
	else
	{

		if (m  < = 2)
			printf("nova\n");
		else if (m <= 96)
			printf("crescente\n");
		else if (m  < = 100)
			printf("cheia\n");

	}
	return 0;

}
Copy The Code & Try With Live Editor

Input

x
+
cmd
0 2

Output

x
+
cmd
nova

#2 Code Example with C++ Programming

Code - C++ Programming


#include <bits/stdc++.h>
 
 
using namespace std;
 
int main()
{
    int a, b;
     
    while(cin >> a >> b)
    {
        if (b  < = 2) cout << "nova\n";
        else if (b  < = 96 && a <= b) cout << "crescente\n";
        else if (3  < = b && b <= 96 && a > b) cout << "minguante\n";
        else if (b  < = 100) cout << "cheia\n";
    }
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
0 2

Output

x
+
cmd
nova

#3 Code Example with Java Programming

Code - Java Programming


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    static Reader in = new Reader(System.in);
    static Writer out = new Writer(System.out);

    public static void main(String[] args) throws IOException {
        int t = in.nextInt();
        int y = in.nextInt();
        if (0  < = y && y <= 2) {
            out.println("nova");
        } else if (97 <= y && y <= 100) {
            out.println("cheia");
        } else {
            out.println((t  <  y) ? "crescente" : "minguante");
        }

        in.close();
        out.flush();
        out.close();
    }

 //////  INPUT / OUTPUT  ///////
    static class Reader implements Closeable {

        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        public Reader(InputStream input) {
            reader = new BufferedReader(
                    new InputStreamReader(input));
            tokenizer = new StringTokenizer("");
        }

        private StringTokenizer getTokenizer() throws IOException {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                String line = nextLine();
                if (line == null) {
                    return null;
                }
                tokenizer = new StringTokenizer(line);
            }
            return tokenizer;
        }

        public boolean hasNext() throws IOException {
            return getTokenizer() != null;
        }

        public String next() throws IOException {
            return hasNext() ? tokenizer.nextToken() : null;
        }

        public String nextLine() throws IOException {
            tokenizer = null;
            return reader.readLine();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public float nextFloat() throws IOException {
            return Float.parseFloat(next());
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public String[] nextStringArray(int size) throws IOException {
            String[] array = new String[size];
            for (int i = 0; i  <  size; i++) {
                array[i] = next();
            }
            return array;
        }

        public int[] nextIntArray(int size) throws IOException {
            int[] array = new int[size];
            for (int i = 0; i  <  size; i++) {
                array[i] = nextInt();
            }
            return array;
        }

        public long[] nextLongArray(int size) throws IOException {
            long[] array = new long[size];
            for (int i = 0; i  <  size; i++) {
                array[i] = nextLong();
            }
            return array;
        }

        public double[] nextDoubleArray(int size) throws IOException {
            double[] array = new double[size];
            for (int i = 0; i  <  size; i++) {
                array[i] = nextDouble();
            }
            return array;
        }

        @Override
        public void close() throws IOException {
            tokenizer = null;
            reader.close();
        }
    }

    static class Writer {

        private final PrintWriter writer;

        public Writer(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public void print(Object... objects) {
            for (int i = 0; i  <  objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

        public void flush() {
            writer.flush();
        }

    }
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
0 2

Output

x
+
cmd
nova

#4 Code Example with Javascript Programming

Code - Javascript Programming


const { readFileSync } = require("node:fs")
const [PA, PB] = readFileSync("/dev/stdin", "utf8")
	.split(" ", 2)
	.map((value) => Number.parseInt(value, 10))

// Moon's phases
// nova -> crescente -> cheia -> minguante -> nova

if (0 <= PB && PB <= 2) console.log("nova")
else if (97 <= PB && PB <= 100) console.log("cheia")
else if (3 <= PB && PB <= 96) console.log(PA > PB ? "minguante" : "crescente")
Copy The Code & Try With Live Editor

Input

x
+
cmd
0 2

Output

x
+
cmd
nova

#5 Code Example with Python Programming

Code - Python Programming


e = str(input()).split()
a = int(e[0])
b = int(e[1])

if a < b:
    if b <= 2: print('nova')
    elif b <= 96: print('crescente')
    else: print('cheia')
else:
    if b >= 97: print('cheia')
    elif b >= 3: print('minguante')
    else: print('nova')
Copy The Code & Try With Live Editor

Input

x
+
cmd
0 2

Output

x
+
cmd
nova
Advertisements

Demonstration


Previous
#1891 Beecrowd Online Judge Solution 1891 Removing Coins in the Kem Kradan Solution in C, C++, Java, Js and Python
Next
#1895 Beecrowd Online Judge Solution 1895 Game of Limit Solution in C, C++, Java, Js and Python