Jump to content

Exercícios DO BEECROW - LÓGICA


Renan Alves

Postagens Recomendadas

beecrowd | 1036

Bhaskara's Formula

Adapted by Neilor Tonin, URI  Brazil

Timelimit: 1

Read 3 floating-point numbers. After, print the roots of bhaskara’s formula. If it's impossible to calculate the roots because a division by zero or a square root of a negative number, presents the message “Impossivel calcular”.

Input

Read 3 floating-point numbers (double) A, B and C.

Output

Print the result with 5 digits after the decimal point or the message if it is impossible to calculate.

Calculo de bhaskara :

Valido para equações de segundo grau = x² + bx + c = 0;

Descriminante Delta = b² - 4 * a * c;

Raiz(x1) = - b + raiz de delta / 2 * a;

Raiz(x2 = -b - raiz de delta / 2 * a;

 

Resolução:

 

 

import java.util.Scanner;

import java.util.Locale;

public class Main {

 

public static void main(String[] args) {

Locale.setDefault(Locale.US);

Scanner sc = new Scanner(System.in);

double a, b, c, R1, R2, delta;

a = sc.nextDouble();

b = sc.nextDouble();

c = sc.nextDouble();

delta = Math.pow(b, 2.0) - 4.0 * a * c;

if(a == 0 || delta <= 0) {

System.out.println("Impossivel calcular");

}

else {

R1 = ( -b + Math.sqrt(delta)) / (2.0 * a);

R2 = ( -b - Math.sqrt(delta)) / (2.0 * a);

System.out.printf("R1 = %.5f\n", R1);

System.out.printf("R2 = %.5f\n", R2);

}

sc.close();

}

}

 

 

Link to comment
Compartilhe em outros sites

beecrowd | 1037

Interval

Adapted by Neilor Tonin, URI  Brazil

Timelimit: 1

You must make a program that read a float-point number and print a message saying in which of following intervals the number belongs: [0,25] (25,50], (50,75], (75,100]. If the read number is less than zero or greather than 100, the program must print the message “Fora de intervalo” that means "Out of Interval".

The symbol '(' represents greather than. For example:
[0,25] indicates numbers between 0 and 25.0000, including both.
(25,50] indicates numbers greather than 25 (25.00001) up to 50.0000000.

Input

The input file contains a floating-point number.

Output

The output must be a message like following example.

 

Resolução:

 

 

import java.util.Scanner;

import java.util.Locale;

 

public class Main {

 

public static void main(String[] args) {

Locale.setDefault(Locale.US);

Scanner sc = new Scanner(System.in);

 

double intervalo = sc.nextDouble();

 

if (intervalo >= 0 && intervalo <= 25.0) {

System.out.println("Intervalo [0,25]");

}

else if (intervalo > 25.0 && intervalo <= 50.0) {

System.out.println("Intervalo (25,50]");

}

else if (intervalo > 50.0 && intervalo <= 75.0) {

System.out.println("Intervalo (50,75]");

}

else if (intervalo > 75.0 && intervalo <= 100.0) {

System.out.println("Intervalo (75,100]");

}

else {

System.out.println("Fora de intervalo");

}

 

sc.close();

 

}

 

}

Editado por Renan Alves
Link to comment
Compartilhe em outros sites

Em 04/02/2024 at 02:35, Renan Alves disse:

Hoje a noite posto mais exercícios resolvidos. 

import random

iniciante = ['1,2,3,4', '2,3,4,5', '3,4,5,6']

monstro = random.randint(0,2)

desafio_n = iniciante[monstro]

print(iniciante[monstro])

vit = int(input('\033[31mDIGITE UM NUMERO: '))

iniciante[monstro] = vit != desafio_n

if desafio_n == vit :

print('d') else: print('v')

estou com problema de lista interagir com input para obter resultado, gostaria que os numeros da lista enteraja com o numero do input

alguem pode me ajudar

  • Curtir 1
Link to comment
Compartilhe em outros sites

3 horas atrás, felipe brasileiro disse:

import random

iniciante = ['1,2,3,4', '2,3,4,5', '3,4,5,6']

monstro = random.randint(0,2)

desafio_n = iniciante[monstro]

print(iniciante[monstro])

vit = int(input('\033[31mDIGITE UM NUMERO: '))

iniciante[monstro] = vit != desafio_n

if desafio_n == vit :

print('d') else: print('v')

estou com problema de lista interagir com input para obter resultado, gostaria que os numeros da lista enteraja com o numero do input

alguem pode me ajudar

Tenta assim:

 

import random iniciante = [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6]]

monstro = random.randint(0, 2)

desafio_n = iniciante[monstro]

print(iniciante[monstro])

vit = int(input('\033[31mDIGITE UM NUMERO: '))

if desafio_n == vit: print('Você venceu!')

else: print('Você perdeu!')

  • Curtir 1
Link to comment
Compartilhe em outros sites

beecrowd | 1038

Snack

Adapted by Neilor Tonin, URI  Brazil

Timelimit: 1

Using the following table, write a program that reads a code and the amount of an item. After, print the value to pay. This is a very simple program with the only intention of practice of selection commands.

https://resources.beecrowd.com.br/gallery/images/problems/UOJ_1038_en.png

Input

The input file contains two integer numbers X and Y. X is the product code and Y is the quantity of this item according to the above table.

Output

The output must be a message "Total: R$ " followed by the total value to be paid, with 2 digits after the decimal point.

 

Resolução:

 

import java.util.Scanner;

import java.util.Locale;

 

public class Main {

 

public static void main(String[] args) {

Locale.setDefault(Locale.US);

Scanner sc = new Scanner(System.in);

 

int codigo, quantidade;

double produto;

codigo = sc.nextInt();

quantidade = sc.nextInt();

if(codigo == 1) {

produto = quantidade * 4.0;

}

else if(codigo == 2) {

produto = quantidade * 4.5;

}

else if(codigo == 3) {

produto = quantidade * 5.0;

}

else if(codigo == 4) {

produto = quantidade * 2.0;

}

else {

produto = quantidade * 1.5;

}

System.out.printf("Total: R$ %.2f\n", produto);

sc.close();

 

}

 

}

Link to comment
Compartilhe em outros sites

beecrowd | 1040

Average 3

Adapted by Neilor Tonin, URI  Brazil

Timelimit: 1

Read four numbers (N1, N2, N3, N4), which one with 1 digit after the decimal point, corresponding to 4 scores obtained by a student. Calculate the average with weights 2, 3, 4 e 1 respectively, for these 4 scores and print the message "Media: " (Average), followed by the calculated result. If the average was 7.0 or more, print the message "Aluno aprovado." (Approved Student). If the average was less than 5.0, print the message: "Aluno reprovado." (Reproved Student). If the average was between 5.0 and 6.9, including these, the program must print the message "Aluno em exame." (In exam student).

In case of exam, read one more score. Print the message "Nota do exame: " (Exam score) followed by the typed score. Recalculate the average (sum the exam score with the previous calculated average and divide by 2) and print the message “Aluno aprovado.” (Approved student) in case of average 5.0 or more) or "Aluno reprovado." (Reproved student) in case of average 4.9 or less. For these 2 cases (approved or reproved after the exam) print the message "Media final: " (Final average) followed by the final average for this student in the last line.

Input

The input contains four floating point numbers that represent the students' grades.

Output

Print all the answers with one digit after the decimal point.

float = é usado quando você necessita de mais precisão nos cálculos com casas decimais.

Resolução:

import java.util.Scanner;

import java.util.Locale;

 

public class Main {

 

public static void main(String[] args) {

Locale.setDefault(Locale.US);

Scanner sc = new Scanner(System.in);

 

float nota1, nota2, nota3, nota4, nota5, media;

nota1 = sc.nextFloat();

nota2 = sc.nextFloat();

nota3 = sc.nextFloat();

nota4 = sc.nextFloat();

media = (nota1 * 2f + nota2 * 3f + nota3 * 4f + nota4) / 10f;

if(media >= 7f) {

System.out.printf("Media: %.1f\n", media);

System.out.println("Aluno aprovado.");

}

else if(media < 5f) {

System.out.printf("Media: %.1f\n", media);

System.out.println("Aluno reprovado.");

}

else {

System.out.printf("Media: %.1f", media);

System.out.println("\nAluno em exame.");

nota5 = sc.nextFloat();

System.out.printf("Nota do exame: %.1f\n", nota5);

media += nota5;

media /= 2f;

if(media >= 5f) {

System.out.println("Aluno aprovado.");

System.out.printf("Media final: %.1f\n", media);

}

else {

System.out.println("Aluno reprovado.");

System.out.printf("Media final: %.1f\n", media);

}

}

sc.close();

 

}

 

}

Link to comment
Compartilhe em outros sites

beecrowd | 1041

Coordinates of a Point

Adapted by Neilor Tonin, URI  Brazil

Timelimit: 1

Write an algorithm that reads two floating values (x and y), which should represent the coordinates of a point in a plane. Next, determine which quadrant the point belongs, or if you are at one of the Cartesian axes or the origin (x = y = 0).

https://resources.beecrowd.com.br/gallery/images/problems/UOJ_1041.png

If the point is at the origin, write the message "Origem".

If the point is at X axis write "Eixo X", else if the point is at Y axis write "Eixo Y".

Input

The input contains the coordinates of a point.

Output

The output should display the quadrant in which the point is.

Resolução:

 

 

import java.util.Locale;

import java.util.Scanner;

 

public class Exercicio_7 {

 

      public static void main(String[] args) {

            Locale.setDefault(Locale.US);

            Scanner sc = new Scanner(System.in);

           

            double x, y;

           

            x = sc.nextDouble();

            y = sc.nextDouble();

           

            if(x == 0 && y == 0) {

                  System.out.println("Origem");

            }

            else if(x == 0) {

                  System.out.println("Eixo Y");

            }

            else if(y == 0) {

                  System.out.println("Eixo X");

            }

            else if(x > 0 && y > 0) {

                  System.out.println("Q1");

            }

            else if(x < 0 && y > 0) {

                  System.out.println("Q2");

            }

            else if(x < 0 && y < 0) {

                  System.out.println("Q3");

            }

            else {

                  System.out.println("Q4");

            }

           

            sc.close();

 

      }

 

}

Link to comment
Compartilhe em outros sites

Em 13/02/2024 at 23:31, Renan Alves disse:

Tenta assim:

 

import random iniciante = [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6]]

monstro = random.randint(0, 2)

desafio_n = iniciante[monstro]

print(iniciante[monstro])

vit = int(input('\033[31mDIGITE UM NUMERO: '))

if desafio_n == vit: print('Você venceu!')

else: print('Você perdeu!')

muito boa essa logica, terminei encontrando outro jeito mais pratico

import random

c = []

while len(c)<4:

   num=random.randint(1,6)

  if num not in c :

      c.append(num)

print('c')

dado = int(input(' dado'))

if dado in c :

 print('vence')

else:

print('derrota')

  • Curtir 1
Link to comment
Compartilhe em outros sites

Em 16/02/2024 at 16:22, felipe brasileiro disse:

muito boa essa logica, terminei encontrando outro jeito mais pratico

import random

c = []

while len(c)<4:

   num=random.randint(1,6)

  if num not in c :

      c.append(num)

print('c')

dado = int(input(' dado'))

if dado in c :

 print('vence')

else:

print('derrota')

Ficou ótimo também, reduz um pouco a leitura do programa

Editado por Renan Alves
Link to comment
Compartilhe em outros sites

beecrowd | 1042

Simple Sort

Adapted by Neilor Tonin, URI  Brazil

Timelimit: 1

Read three integers and sort them in ascending order. After, print these values in ascending order, a blank line and then the values in the sequence as they were readed.

Input

The input contains three integer numbers.

Output

Present the output as requested above.

 

Resolução:

 

 

import java.util.Scanner;

import java.util.Locale;

 

public class Main {

 

public static void main(String[] args) {

Locale.setDefault(Locale.US);

Scanner sc = new Scanner(System.in);

int a, b, c, menor, medio, maior;

a = sc.nextInt();

b = sc.nextInt();

c = sc.nextInt();

if(a > b && a > c) {

maior = a;

if(b > c) {

medio = b;

menor = c;

}

else {

medio = c;

menor = b;

}

}

else if(b > c) {

maior = b;

if(c > a) {

medio = c;

menor = a;

}

else {

medio = a;

menor = c;

}

}

else {

maior = c;

if(b > a) {

medio = b;

menor = a;

}

else {

medio = a;

menor = b;

}

}

System.out.println(menor);

System.out.println(medio);

System.out.println(maior);

System.out.println();

System.out.println(a);

System.out.println(b);

System.out.println(c);

sc.close();

}

 

}

Link to comment
Compartilhe em outros sites

beecrowd | 1043

Triangle

Adapted by Neilor Tonin, URI  Brazil

Timelimit: 1

Read three point floating values (A, B and C) and verify if is possible to make a triangle with them. If it is possible, calculate the perimeter of the triangle and print the message:


Perimetro = XX.X


If it is not possible, calculate the area of the trapezium which basis A and B and C as height, and print the message:


Area = XX.X

Input

The input file has tree floating point numbers.

Output

Print the result with one digit after the decimal point.

 

Resolução:

 

 

import java.util.Scanner;
import java.util.Locale;

public class Main {

    public static void main(String[] args) {
        Locale.setDefault(Locale.US);
        Scanner sc = new Scanner(System.in);
        
        double a, b, c, resultado;
        
        a = sc.nextDouble();
        b = sc.nextDouble();
        c = sc.nextDouble();
        
        if(a + b > c && a + c > b && b + c > a) {
            resultado = a + b + c;
            System.out.printf("Perimetro = %.1f\n", resultado);
        }
        else {
            resultado = (a + b) * c / 2.0;
            System.out.printf("Area = %.1f\n", resultado);
        }
        
        
        
        sc.close();
    }

}

Link to comment
Compartilhe em outros sites

beecrowd | 1044

Multiples

Adapted by Neilor Tonin, URI  Brazil

Timelimit: 1

Read two integer values (A and B). After, the program should print the message "Sao Multiplos" (are multiples) or "Nao sao Multiplos" (aren’t multiples), corresponding to the read values.

Input

The input has two integer numbers.

Output

Print the relative message to the input as stated above.

 

Resolução:

 

 

import java.util.Scanner;

import java.util.Locale;

 

public class Main {

 

public static void main(String[] args) {

Locale.setDefault(Locale.US);

Scanner sc = new Scanner(System.in);

int a, b;

a = sc.nextInt();

b = sc.nextInt();

if(a % b == 0 || b % a == 0) {

System.out.println("Sao Multiplos");

}

else {

System.out.println("Nao sao Multiplos");

}

sc.close();

}

 

}

Link to comment
Compartilhe em outros sites

beecrowd | 1045

Triangle Types

Adapted by Neilor Tonin, URI  Brazil

Timelimit: 1

Read 3 double numbers (A, B and C) representing the sides of a triangle and arrange them in decreasing order, so that the side A is the biggest of the three sides. Next, determine the type of triangle that they can make, based on the following cases always writing an appropriate message:

if A ≥ B + C, write the message: NAO FORMA TRIANGULO

if A2 = B2 + C2, write the message: TRIANGULO RETANGULO

if A2 > B2 + C2, write the message: TRIANGULO OBTUSANGULO

if A2 < B2 + C2, write the message: TRIANGULO ACUTANGULO

if the three sides are the same size, write the message: TRIANGULO EQUILATERO

if only two sides are the same and the third one is different, write the message: TRIANGULO ISOSCELES

Input

The input contains three double numbers, A (0 < A) , B (0 < B) and C (0 < C).

Output

Print all the classifications of the triangle presented in the input.

 

Resolução:

 

 

import java.util.Scanner;

import java.util.Locale;

 

public class Main {

 

public static void main(String[] args) {

Locale.setDefault(Locale.US);

Scanner sc = new Scanner(System.in);

double a, b, c;

double A, B, C;

a = sc.nextDouble();

b = sc.nextDouble();

c = sc.nextDouble();

A = Math.max(a, Math.max(b, c));

B = 0;

C = 0;

if(A == a) {

B = Math.max(b, c);

C = Math.min(b, c);

}

if(A == b) {

B = Math.max(a, c);

C = Math.min(a, c);

}

if(A == c) {

B = Math.max(a, b);

C = Math.min(a, b);

}

if(A >= (B + C)) {

System.out.println("NAO FORMA TRIANGULO");

}

else if(A * A == B * B + C * C) {

System.out.println("TRIANGULO RETANGULO");

}

else if(A * A > B * B + C * C) {

System.out.println("TRIANGULO OBTUSANGULO");

}

else {

System.out.println("TRIANGULO ACUTANGULO");

}

if(A == B && B == C) {

System.out.println("TRIANGULO EQUILATERO");

}

else if(A == B && A != C|| A == C && A != B || B == C && B != A){

System.out.println("TRIANGULO ISOSCELES");

}

sc.close();

}

}

Link to comment
Compartilhe em outros sites

beecrowd | 1046

Game Time

Adapted by Neilor Tonin, URI  Brazil

Timelimit: 1

Read the start time and end time of a game, in hours. Then calculate the duration of the game, knowing that the game can begin in a day and finish in another day, with a maximum duration of 24 hours. The message must be printed in portuguese “O JOGO DUROU X HORA(S)” that means “THE GAME LASTED X HOUR(S)”

Input

Two integer numbers representing the start and end time of a game.

Output

Print the duration of the game as in the sample output.

 

Resolução:

 

 

import java.util.Scanner;

import java.util.Locale;

 

public class Main {

 

public static void main(String[] args) {

Locale.setDefault(Locale.US);

Scanner sc = new Scanner(System.in);

int inicio, fim, tempo;

int dia1 = sc.nextInt();

int dia2 = sc.nextInt();

if(dia1 < dia2) {

tempo = dia2 - dia1;

}

else {

tempo = 24 - dia1 + dia2;

}

System.out.println("O JOGO DUROU " + tempo + " HORA(S)");

}

}

Link to comment
Compartilhe em outros sites

beecrowd | 1047

Game Time with Minutes

Adapted by Neilor Tonin, URI  Brazil

Timelimit: 1

Read the start time and end time of a game, in hours and minutes (initial hour, initial minute, final hour, final minute). Then print the duration of the game, knowing that the game can begin in a day and finish in another day,

Obs.: With a maximum game time of 24 hours and the minimum game time of 1 minute.

Input

Four integer numbers representing the start and end time of the game.

Output

Print the duration of the game in hours and minutes, in this format: “O JOGO DUROU XXX HORA(S) E YYY MINUTO(S)” . Which means: the game lasted XXX hour(s) and YYY minutes.

 

Resolução:

 

 

import java.util.Scanner;

import java.util.Locale;

 

public class Main {

 

public static void main(String[] args) {

Locale.setDefault(Locale.US);

Scanner sc = new Scanner(System.in);

int hora1, minuto1, hora2, minuto2, inicio, fim, duracao, hora, minuto;

hora1 = sc.nextInt();

minuto1 = sc.nextInt();

hora2 = sc.nextInt();

minuto2 = sc.nextInt();

/* Converter horas em minutos

*/

inicio = hora1 * 60 + minuto1;

fim = hora2 * 60 + minuto2;

if(inicio < fim) {

duracao = fim - inicio; // subtração do fim pelo inicio do evento.

}

else {

duracao = (60 * 24 - inicio) + fim; // multiplicar as horas por minuto e subtrair pelos minutos do inicio.

}

hora = duracao / 60;  //converter minutos em horas

minuto = duracao % 60;  // sobra da conversao dos minutos para horas, a quais a sobra é considerada minuto.

System.out.println("O JOGO DUROU " + hora + " HORA(S) E " + minuto + " MINUTO(S)");

sc.close();

}

}

Link to comment
Compartilhe em outros sites

beecrowd | 1048

Salary Increase

By Neilor Tonin, URI  Brazil

Timelimit: 1

The company ABC decided to give a salary increase to its employees, according to the following table:

 

Salary Readjustment    Rate

0 - 400.00                        15%
400.01 - 800.00              12% 
800.01 - 1200.00             10%
1200.01 - 2000.00           7%
Above 2000.00              4%


Read the employee's salary, calculate and print the new employee's salary, as well the money earned and the increase percentual obtained by the employee, with corresponding messages in Portuguese, as the below example.

Input

The input contains only a floating-point number, with 2 digits after the decimal point.

Output

Print 3 messages followed by the corresponding numbers (see example) informing the new salary, the among of money earned (both must be shown with 2 decimal places) and the percentual obtained by the employee. Note:
Novo salario:  means "New Salary"
Reajuste ganho: means "Money earned"
Em percentual: means "In percentage"

 

Resolução:

 

 

import java.util.Scanner;

import java.util.Locale;

 

public class Main {

 

public static void main(String[] args) {

Locale.setDefault(Locale.US);

Scanner sc = new Scanner(System.in);

double salario, porcentagem, soma, percentual;

salario = sc.nextDouble();

if(salario >= 0 && salario <= 400.0) {

porcentagem = 15.0;

}

else if (salario > 400.0 && salario <= 800.0) {

porcentagem = 12.0;

}

else if (salario > 800.0 && salario <= 1200.0) {

porcentagem = 10.0;

}

else if (salario > 1200.0 && salario <= 2000.0) {

porcentagem = 7.0;

}

else {

porcentagem = 4.0;

}

percentual = (salario / 100.0) * porcentagem;

soma = percentual + salario;

System.out.printf("Novo salario: %.2f\n", soma);

System.out.printf("Reajuste ganho: %.2f\n", percentual);

System.out.printf("Em percentual: %.0f %%\n", porcentagem);

sc.close();

}

}

 

Obs: para escrever o simbolo de %, utilizamos %%.

Link to comment
Compartilhe em outros sites

beecrowd | 1050

DDD

Adapted by Neilor Tonin, URI  Brazil

Timelimit: 1

Read an integer number that is the code number for phone dialing. Then, print the destination according to the following table:

61      -       Brasilia

71      -       Salvador

11      -        Sao Paulo

21      -       Rio de Janeiro

32      -      Juiz de Fora

19      -       Campinas

27      -       Vitoria

31      -       Belo Horizonte

qualquer ddd digitado fora desse escopo, o resultado vai ter que ser "DDD nao cadastrado".

 

If the input number isn’t found in the above table, the output must be:
DDD nao cadastrado
That means “DDD not found” in Portuguese language.

Input

The input consists in a unique integer number.

Output

Print the city name corresponding to the input DDD. Print DDD nao cadastrado if doesn't exist corresponding DDD to the typed number.

 

Resolução:

 

 

import java.util.Scanner;

import java.util.Locale;

 

public class Main {

 

public static void main(String[] args) {

Locale.setDefault(Locale.US);

Scanner sc = new Scanner(System.in);

int ddd = sc.nextInt();

String estado;

if(ddd == 61) {

estado = "Brasilia";

}

else if(ddd == 71) {

estado = "Salvador";

}

else if(ddd == 11) {

estado = "Sao Paulo";

}

else if(ddd == 21) {

estado = "Rio de Janeiro";

}

else if(ddd == 32) {

estado = "Juiz de Fora";

}

else if(ddd == 19) {

estado = "Campinas";

}

else if(ddd == 27) {

estado = "Vitoria";

}

else if(ddd == 31) {

estado = "Belo Horizonte";

}

else {

estado = "DDD nao cadastrado";

}

System.out.println(estado);

sc.close();

}

}

Link to comment
Compartilhe em outros sites

beecrowd | 1051

Taxes

By Neilor Tonin, URI  Brasil

Timelimit: 1

In an imaginary country called Lisarb, all the people are very happy to pay their taxes because they know that doesn’t exist corrupt politicians and the taxes are used to benefit the population, without any misappropriation. The currency of this country is Rombus, whose symbol is R$.

Read a value with 2 digits after the decimal point, equivalent to the salary of a Lisarb inhabitant. Then print the due value that this person must pay of taxes, according to the table below.

Remember, if the salary is R$ 3,002.00 for example, the rate of 8% is only over R$ 1,000.00, because the salary from R$ 0.00 to R$ 2,000.00 is tax free. In the follow example, the total rate is 8% over R$ 1000.00 + 18% over R$ 2.00, resulting in R$ 80.36 at all. The answer must be printed with 2 digits after the decimal point.

Input

The input contains only a float-point number, with 2 digits after the decimal point.

Output

Print the message "R$" followed by a blank space and the total tax to be payed, with two digits after the decimal point. If the value is up to 2000, print the message "Isento".

 

Resolução:

 

 

import java.util.Scanner;

import java.util.Locale;

 

public class Main {

 

public static void main(String[] args) {

Locale.setDefault(Locale.US);

Scanner sc = new Scanner(System.in);

double valor, taxas = 0;

valor = sc.nextDouble();

if(valor >= 0 && valor <= 2000.0) {

System.out.println("Isento");

}

else if(valor > 2000.0 && valor <= 3000.0) {

taxas = (valor - 2000) / 100.0 * 8.0;

}

else if(valor > 3000.0 && valor <= 4500.0) {

taxas = (valor - 3000.0) / 100.0 * 18.0 + 1000.0 / 100.0 * 8.0;

}

else {

taxas = (valor - 4500.0) / 100.0 * 28.0 + 1500.0 / 100 * 18.0 + 1000.0 / 100.0 * 8.0;

}

if(taxas > 0.0) {

System.out.printf("R$ %.2f\n" , taxas);

}

sc.close();

}

}

imagem_2024-02-24_024700252.png

Link to comment
Compartilhe em outros sites

beecrowd | 1052

Month

Adapted by Neilor Tonin, URI  Brazil

Timelimit: 1

Read an integer number between 1 and 12, including. Corresponding to this number, you must print the month of the year, in english, with the first letter in uppercase.

Input

The input contains only an integer number.

Output

Print the name of the month according to the input number, with the first letter in uppercase.

 

Sintaxe opcional - Switch case:

 

 

import java.util.Scanner;
import java.util.Locale;

public class Main {

    public static void main(String[] args) {
        Locale.setDefault(Locale.US);
        Scanner sc = new Scanner(System.in);

        int mounth;
        String mes;

        switch(mounth = sc.nextInt()) {
        case 1:
            mes = "January";
            break;
        case 2:
            mes = "February";
            break;
        case 3:
            mes = "March";
            break;
        case 4:
            mes = "April";
            break;
        case 5:
            mes = "May";
            break;
        case 6:
            mes = "June";
            break;
        case 7:
            mes = "July";
            break;
        case 8:
            mes = "August";
            break;
        case 9:
            mes = "September";
            break;
        case 10:
            mes = "October";
            break;
        case 11:
            mes = "November";
            break;
        default:
            mes = "December";
        }

        System.out.println(mes);

        sc.close();

    }

}

Link to comment
Compartilhe em outros sites

beecrowd | 1059

Even Numbers

Adapted by Neilor Tonin, URI  Brazil

Timelimit: 1

Write a program that prints all even numbers between 1 and 100, including them if it is the case.

Input

In this extremely simple problem there is no input.

Output

Print all even numbers between 1 and 100, including them, one by row.

 

Resolução:

 

 

public class Main {

 

public static void main(String[] args) {

for(int i = 1; i <= 100; i++) {

if(i % 2 == 0) {

System.out.println(i);

}

}

 

}

 

}

Link to comment
Compartilhe em outros sites

beecrowd | 1060

Positive Numbers

Adapted by Neilor Tonin, URI  Brazil

Timelimit: 1

Write a program that reads 6 numbers. These numbers will only be positive or negative (disregard null values). Print the total number of positive numbers.

Input

Six numbers, positive and/or negative.

Output

Print a message with the total number of positive numbers.

 

Resolução:

 

import java.util.Locale;

import java.util.Scanner;

 

public class Main {

 

public static void main(String[] args) {

Locale.setDefault(Locale.US);

Scanner sc = new Scanner(System.in);

double n;

int positivo = 0;

 

for (int i = 1; i <= 6; i++) {

n = sc.nextDouble();

if (n >= 0) {

positivo++;

}

}

System.out.println(positivo + " valores positivos");

sc.close();

 

}

 

}

Link to comment
Compartilhe em outros sites

beecrowd | 1061

Event Time

Adapted by Neilor Tonin, URI  Brazil

Timelimit: 1

Peter is organizing an event in his University. The event will be in April month, beginning and finishing within April month. The problem is: Peter wants to calculate the event duration in seconds, knowing obviously the begin and the end time of the event.

You know that the event can take from few seconds to some days, so, you must help Peter to compute the total time corresponding to duration of the event.

Input

The first line of the input contains information about the beginning day of the event in the format: “Dia xx”. The next line contains the start time of the event in the format presented in the sample input. Follow 2 input lines with same format, corresponding to the end of the event.

Output

Your program must print the following output, one information by line, considering that if any information is null for example, the number 0 must be printed in place of W, X, Y or Z:

W dia(s)
X hora(s)
Y minuto(s)
Z segundo(s)

Obs: Consider that the event of the test case have the minimum duration of one minute. “dia” means day, “hora” means hour, “minuto” means minute and “Segundo” means second in Portuguese.

 

Resolução:

 

import java.util.Locale;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Locale.setDefault(Locale.US);
        Scanner sc = new Scanner(System.in);
        
        String d, p;
        int dia1, hora1, minuto1, segundo1;
        int dia2, hora2, minuto2, segundo2;
        
        //hora inicial;
        d = sc.next();
        dia1 = sc.nextInt();
        hora1 = sc.nextInt();
        p = sc.next();
        minuto1 = sc.nextInt();
        p = sc.next();
        segundo1 = sc.nextInt();
        
        //fim do evento;
        d = sc.next();
        dia2 = sc.nextInt();
        hora2 = sc.nextInt();
        p = sc.next();
        minuto2 = sc.nextInt();
        p = sc.next();
        segundo2 = sc.nextInt();
        
        int inicio = 24 * 60 * 60 * dia1 + hora1 * 60 * 60 + minuto1 * 60 + segundo1;
        int fim = 24 * 60 * 60 * dia2 + hora2 * 60 * 60 + minuto2 * 60 + segundo2;
        int fim_Do_Evento = (fim - inicio) / (24 * 60 * 60);
        int dia = (fim - inicio) % (24 * 60 * 60);
        int hora = dia / (60 * 60);
        int resto = dia % (60 * 60);
        int minuto = resto / 60;
        int segundo = resto % 60;
        
        System.out.println(fim_Do_Evento + " dia(s)");
        System.out.println(hora + " hora(s)");
        System.out.println(minuto + " minuto(s)");
        System.out.println(segundo + " segundo(s)");
        
        sc.close();

    }

}
 

Link to comment
Compartilhe em outros sites

beecrowd | 1064

Positives and Average

Adapted by Neilor Tonin, URI  Brazil

Timelimit: 1

Read 6 values that can be floating point numbers. After, print how many of them were positive. In the next line, print the average of all positive values typed, with one digit after the decimal point.

Input

The input consist in 6 numbers that can be integer or floating point values. At least one number will be positive.

Output

The first output value is the amount of positive numbers. The next line should show the average of the positive values typed.

 

Resolução:

 

import java.util.Locale;

import java.util.Scanner;

 

public class Main {

 

public static void main(String[] args) {

Locale.setDefault(Locale.US);

Scanner sc = new Scanner(System.in);

double n, positivo = 0, media = 0;

for(int i = 1; i <= 6; i++) {

n = sc.nextDouble();

if(n >= 0) {

media += n;

positivo++;

}

}

media /= positivo;

System.out.printf("%.0f valores positivos\n", positivo);

System.out.printf("%.1f\n", media);

 

}

 

}

 

 

Link to comment
Compartilhe em outros sites

Crie uma conta ou entre para comentar 😀

Você precisa ser um membro para deixar um comentário.

Crie a sua conta

Participe da nossa comunidade, crie sua conta.
É bem rápido!

Criar minha conta agora

Entrar

Você já tem uma conta?
Faça o login agora.

Entrar agora
  • Quem está online   0 Membros, 0 Anônimos, 37 Visitantes (Ver lista completa)

    • There are no registered users currently online



×
×
  • Create New...