-
Notifications
You must be signed in to change notification settings - Fork 18
/
TimeJump.java
47 lines (38 loc) · 2.4 KB
/
TimeJump.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
====================================================
Desafio Java - Cognizant Developer
====================================================
1/3 - Andando no Tempo
====================================================
Desafio
Imagine o seguinte cenário, você desenvolveu uma máquina de teletransporte no tempo que pode ser usada no máximo três vezes, e a cada uso da máquina você pode escolher ir para o futuro ou voltar para o passado. A máquina possui três créditos fixos; cada crédito representa uma certa quantidade de anos, e pode ser usado para ir essa quantidade de anos para o passado ou para o futuro. Você pode fazer uma, duas ou três viagens, e cada um desses três créditos pode ser usado uma vez apenas. Por exemplo, se os créditos forem 5, 12 e 9, você poderia decidir fazer duas viagens: ir 5 anos para o futuro e, depois, voltar 9 anos para o passado. Dessa forma, você terminaria quatro anos no passado, em 2012. Também poderia fazer três viagens, todas indo para o futuro, usando os créditos em qualquer ordem, terminando em 2042.
Neste desafio, dados os valores dos três créditos da máquina, seu programa deve dizer se é ou não possível viajar no tempo e voltar para o presente, fazendo pelo menos uma viagem e, no máximo, três viagens; sempre usando cada um dos três créditos no máximo uma vez.
Entrada
A entrada consiste de uma linha contendo os valores dos três créditos A, B e C (1 ≤ A, B, C ≤ 1000).
Saída
Seu programa deve imprimir uma linha contendo o caracter “S” se é poss ível viajar e voltar para o presente, ou “N” caso contrário.
-----------------------------------------
| Exemplo de Entrada | Exemplo de Saída |
-----------------------------------------
| 22 5 22 | S |
-----------------------------------------
| 31 110 79 | S |
-----------------------------------------
| 45 8 7 | N |
-----------------------------------------
SOLUÇÃO ABAIXO: */
import java.io.IOException;
import java.util.Scanner;
public class TimeJump {
public static void main(String[] args) throws IOException {
Scanner leitor = new Scanner(System.in);
int a = leitor.nextInt();
int b = leitor.nextInt();
int c = leitor.nextInt();
if (a == b || a == c || b == c || a + b == c || a + c == b || b + c == a)
System.out.println("S");
else
System.out.println("N");
leitor.close();
}
}