Last active
October 19, 2017 15:53
-
-
Save diogocapela/6dbed6f5718b4aed7fa65765d9e7f27e to your computer and use it in GitHub Desktop.
APROG - PL02 Algoritmia
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ED: input1, input2, input3, numero, raiz | |
INÍCIO | |
LER(input1) | |
LER(input2) | |
SE(input2 <= input1) | |
ESCREVER('Os número devem ser introduzidos por ordem crescente.') | |
FIMSE | |
SE(input2 > input1) | |
LER(input3) | |
SE(input3 <= input2) | |
ESCREVER('Os número devem ser introduzidos por ordem crescente.') | |
FIMSE | |
SE(input3 > input2) | |
numero = input1 * 10^2 + input2 * 10^1 + input1 * 10^0 | |
raiz = numero^(0.5) | |
ESCREVER('O número introduzido foi: ' + numero) | |
ESCREVER('A raiz quadrada do número introduzido é: ' + raiz) | |
FIMSE | |
FIMSE | |
FIM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ED: precoNormal, precoSaldo | |
INÍCIO | |
LER(precoNormal) | |
ENQUANTO(precoNormal <= 0) | |
ESCREVER('Preco introduzido incorrecto. Por favor introduza o preço novamente.') | |
LER(precoNormal) | |
FIMENQUANTO | |
SE(precoNormal > 200) | |
precoSaldo = precoNormal * 0.4 | |
FIMSE | |
SE(precoNormal <= 200 && precoNormal > 100) | |
precoSaldo = precoNormal * 0.6 | |
FIMSE | |
SE(precoNormal <= 100 && precoNormal > 50) | |
precoSaldo = precoNormal * 0.7 | |
FIMSE | |
SE(precoNormal <= 50) | |
precoSaldo = precoNormal * 80 | |
FIMSE | |
ESCREVER('O preço do artigo em saldo é de ' + precoSaldo + '.') | |
FIM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ED: a, b, c | |
INÍCIO | |
LER(a, b, c) | |
ENQUANTO(a <= 0 || b <= 0 || c <= 00 || a + b + c != 180) | |
ESCREVER('Ângulos introduzidos incorrecto. Por favor insira os dados novamente.') | |
LER(a, b, c) | |
FIMENQUANTO | |
SE(a == 90 || b == 90 || c == 90) | |
ESCREVER('Triângulo rectangulo.') | |
FIMSE | |
SE(a > 90 || b > 90 || c > 90) | |
ESCREVER('Triângulo obtusângulo.') | |
FIMSE | |
SE(a < 90 && b < 90 && c < 90) | |
ESCREVER('Triângulo acutângulo.') | |
FIMSE | |
FIM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ED Input: partidaH, partidaM, duracaoH, partidaM | |
ED Processo: chegadaH, chegadaM, chegaNoDiaSeguinte | |
INÍCIO | |
// Calcular as horas e minutos de chegada (sem ajustes) | |
chegadaM = partidaM + duracaoM | |
chegadaH = partidaH + duracaoH | |
// Ajustar os minutos de chegada | |
ENQUANTO(chegadaM >= 60) | |
chegadaM = chegadaM - 60 | |
chegadaH = chegadaH + 1 | |
FIMENQUANTO | |
// Ajustar as horas de chegada | |
SE(chegadaH >= 24) | |
chegadaH = chegadaH - 24 | |
chegaNoDiaSeguinte = true | |
FIMSE | |
FIM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Variáveis de input | |
// ---------------------------- | |
let inicioHr = 18; | |
let inicioMin = 22; | |
let inicioSeg = 54; | |
let duracaoTotalEmSeg = 6620; | |
// Variáveis de processamento | |
// ---------------------------- | |
let duracaoHr; | |
let duracaoMin; | |
let duracaoSeg; | |
let finalHr; | |
let finalMin; | |
let finalSeg; | |
// Algoritmo | |
// ---------------------------- | |
// Verificação dos inputs | |
if (inicioHr < 0 || inicioHr > 23 || inicioMin < 0 || inicioMin > 59 || inicioSeg < 0 || inicioSeg > 59 || duracaoTotalEmSeg < 0) { | |
console.log('Dados introduzidos incorrectos.'); | |
// Caso todos os inputs estejam correctos continuar | |
} else { | |
// Ver quantas horas temos no total de segundos | |
duracaoHr = Math.floor(duracaoTotalEmSeg / 3600); | |
// Remover as horas do total de segundos | |
duracaoTotalEmSeg = duracaoTotalEmSeg % 3600; | |
// Ver quantos minutos temos no total de segundos restante | |
duracaoMin = Math.floor(duracaoTotalEmSeg / 60); | |
// Remover as horas do total de segundos restante | |
duracaoTotalEmSeg = duracaoTotalEmSeg % 60; | |
// Passar para a variavél duracaoSeg o total de segundos que restou | |
duracaoSeg = duracaoTotalEmSeg; | |
// Calcular as horas do fim (sem ajutes) | |
finalHr = inicioHr + duracaoHr; | |
// Calcular os minutos do fim (sem ajutes) | |
finalMin = inicioMin + duracaoMin; | |
// Calcular os segundos do fim (sem ajutes) | |
finalSeg = inicioSeg + duracaoSeg; | |
// Ajustar os segudos (enquanto os segundos finais forem superior a 59, subtrair 60 aos segundos finais e adicionar 1 aos minutos finais) | |
while (finalSeg > 59) { | |
finalSeg = finalSeg - 60; | |
finalMin++; | |
} | |
// Ajustar os minutos (enquanto os minutos finais forem superior a 59, subtrair 60 aos minutos finais e adicionar 1 às horas finais) | |
while (finalMin > 59) { | |
finalMin = finalMin - 60; | |
finalHr++; | |
} | |
// Ajutar as horas (enquanto as horas finais forem superior a 23, subtrair 24 às horas finais) | |
while (finalHr > 23) { | |
finalHr = finalHr - 24; | |
} | |
// Mensagem com a hora de início da tarefa | |
console.log('Hora de início:'); | |
console.log(`${inicioHr}:${inicioMin}:${inicioSeg}`); | |
// Mensagem com o tempo de duração da tarefa | |
console.log('Tempo de duração:'); | |
console.log(`${duracaoHr}:${duracaoMin}:${duracaoSeg}`); | |
// Mensagem com a hora de finalização da tarefa | |
console.log('Hora de finalização:'); | |
console.log(`${finalHr}:${finalMin}:${finalSeg}`); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ED: p1x, p1y, p2x, p2y, distancia | |
INÍCIO | |
LER(p1x, p1y, p2x, p2y) | |
distancia = (((p2x - p1x)^2) + ((p2y - p1y)^2))^0.5 | |
ESCREVER('A distância entre os dois pontos é de ' + distancia + '.') | |
FIM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ED: totalSegundos, horas, minutos, segundos, contentorSegundos | |
INÍCIO | |
// Remover os dias inteiros do total em segundos | |
ENQUANTO(totalSegundos >= 86400) | |
totalSegundos = totalSegundos - 86400 | |
FIMENQUANTO | |
// Calcular quantas horas estão no total de segundos restantes | |
horas = totalSegundos DIV 3600 | |
contentorSegundos = totalSegundos - (totalSegundos MOD 3600) | |
// Calcular quantos minutos estão no total de segundos restantes | |
minutos = contentorSegundos DIV 60 | |
contentorSegundos = contentorSegundos - (contentorSegundos MOD 60) | |
// Calcular quantos segundos estão no total de segundos restantes | |
segundos = contentorSegundos | |
// Escrever a mensagem | |
SE(totalSegundos >= 21600 && totalSegundos < 43201) | |
ESCREVER('Bom dia.') | |
ENTÂO SE(totalSegundos >= 43201 && totalSegundos < 72001) | |
ESCREVER('Boa tarde.') | |
SENÃO | |
ESCREVER('Boa noite.') | |
FIMSE | |
// Escrever a hora | |
ESCREVER(horas + ':' + minutos + ':' + segundos) | |
FIM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ED Input: area, precoLitroTinta, rendimentoLitroTinta, salarioDiaPintor | |
ED Processo: litrosDeTintaNecessarios, precoDeTintaNecessaria, numeroPintores, numeroDiasNecessarios, custoMaoObra, custoTinta, custoTotal | |
INÍCIO | |
LER(area, precoLitroTinta, rendimentoLitroTinta, salarioDiaPintor) | |
SE(area <= 0) | |
ESCREVER ('Área introduzida incorrecta.') | |
ENTÃO SE(0 <= area < 100) | |
numeroPintores = 1 | |
ENTÃO SE(100 <= area < 300) | |
numeroPintores = 2 | |
ENTÃO SE(300 <= area < 1000) | |
numeroPintores = 3 | |
SENÃO | |
numeroPintores = 4 | |
FIMSE | |
numeroDiasNecessarios = area / (numeroPintores * 16) | |
SE(numeroDiasNecessarios MOD 2 != 0) | |
numeroDiasNecessarios = (area DIV (numeroPintores * 16)) + 1 | |
FIMSE | |
custoMaoObra = numeroPintores * salarioDiaPintor * numeroDiasNecessarios | |
litrosDeTintaNecessarios = area / rendimentoLitroTinta | |
precoDeTintaNecessaria = litrosDeTintaNecessarios * precoLitroTinta | |
ESCREVER('O custo da mão de obra é de ' + custoMaoObra + '€.') | |
ESCREVER('O custo total da tinta é de ' + precoDeTintaNecessaria + '€.') | |
ESCREVER ('O custo total da obra vai ser de ' custoMaoObra + precoDeTintaNecessaria + '€.') | |
FIM |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment