├── 01-IntroducaoAProgramacaoComJavaScript ├── 1-3-VisitaNaFeira │ └── teste#1.js ├── 2-3-MultiplicacaoSimples │ └── teste#2.js └── 3-3-FolhaDePagamento │ └── teste#3.js ├── 02-FundamentosAritmeticosEmJavaScript ├── 1-5-QuantidadeDeNumerosPositivos │ └── teste#1.js ├── 2-5-ExibindoNumerosPares │ └── teste#2.js ├── 3-5-AnaliseDeNumeros │ └── teste#3.js ├── 4-5-ContagemDeCedulas │ └── teste#4.js └── 5-5-ConsumoMedioDoAutomovel │ └── teste#5.js ├── 03-OrdenacaoEFiltrosEmJavaScript ├── 1-5-OrdenandoNumerosParesEImpares │ └── Teste#1.js ├── 2-5-ComprasNoSupermercado │ └── Teste#2.js ├── 3-5-UniformesDeFinalDeAno │ └── Teste#3.js ├── 4-5-FilaDoBanco │ └── Teste#4.js └── 5-5-GincanaNoAcampamento │ └── Teste#5.js ├── 04-IntroduçãoABuscaE SubstituiçãoEmJavaScript ├── 1-5-OrdenacaoDePalavrasPorTamanho │ └── Teste1-5.js ├── 2-5-EncontreAMaiorSubstring │ └── Teste2-5.js ├── 3-5-ValidadorDeSenhasComRequisitos │ └── Teste3-5.js ├── 4-5-PedraPapelTesouraLagartoESpock │ └── Teste4-5.js └── 5-5-AtalhosParaOWebloggerBrasil │ └── Teste5-5.js └── 05-SolucaoDeProblemasComJavaScript └── 1-7-ContagemRepetidaDeNumeros └── Teste#1.js /01-IntroducaoAProgramacaoComJavaScript/1-3-VisitaNaFeira/teste#1.js: -------------------------------------------------------------------------------- 1 | let line = gets().split(" "); 2 | let A = parseInt(line[0]); 3 | let B = parseInt(line[1]); 4 | let total = A + B; 5 | console.log("X = " + total); -------------------------------------------------------------------------------- /01-IntroducaoAProgramacaoComJavaScript/2-3-MultiplicacaoSimples/teste#2.js: -------------------------------------------------------------------------------- 1 | let valor1 = parseInt(gets()); 2 | let valor2 = parseInt(gets()); 3 | let total = valor1 * valor2; // Altere o valor da variável com o cálculo esperado 4 | console.log(`PROD = ${total}`); -------------------------------------------------------------------------------- /01-IntroducaoAProgramacaoComJavaScript/3-3-FolhaDePagamento/teste#3.js: -------------------------------------------------------------------------------- 1 | let valor1 = parseInt(gets()); 2 | let valor2 = parseInt(gets()); 3 | let valor3 = parseFloat(gets()); 4 | let salary = parseFloat(valor2 * valor3).toFixed(2); // Digite aqui o calculo do salário 5 | console.log("NUMBER = " + valor1); 6 | console.log("SALARY = U$ " + salary); -------------------------------------------------------------------------------- /02-FundamentosAritmeticosEmJavaScript/1-5-QuantidadeDeNumerosPositivos/teste#1.js: -------------------------------------------------------------------------------- 1 | numero = Array(6); 2 | numero[0] = gets(); 3 | numero[1] = gets(); 4 | numero[2] = gets(); 5 | numero[3] = gets(); 6 | numero[4] = gets(); 7 | numero[5] = gets(); 8 | positivos = numero.filter(value => value > 0); 9 | console.log(positivos.length + " valores positivos"); -------------------------------------------------------------------------------- /02-FundamentosAritmeticosEmJavaScript/2-5-ExibindoNumerosPares/teste#2.js: -------------------------------------------------------------------------------- 1 | let numero = gets(); 2 | let par = 2; 3 | while (par <= numero){ 4 | console.log(par); 5 | par = par + 2; 6 | } 7 | -------------------------------------------------------------------------------- /02-FundamentosAritmeticosEmJavaScript/3-5-AnaliseDeNumeros/teste#3.js: -------------------------------------------------------------------------------- 1 | numero = Array(5); 2 | numero[0] = gets(); 3 | numero[1] = gets(); 4 | numero[2] = gets(); 5 | numero[3] = gets(); 6 | numero[4] = gets(); 7 | positivos = numero.filter(value => value > 0); 8 | negativos = numero.filter(value => value < 0); 9 | pares = numero.filter(value => value % 2 == 0); 10 | impares = numero.filter(value => value % 2 != 0); 11 | console.log(pares.length + " valor(es) par(es)"); 12 | console.log(impares.length + " valor(es) impar(es)"); 13 | console.log(positivos.length + " valor(es) positivo(s)"); 14 | console.log(negativos.length + " valor(es) negativo(s)") -------------------------------------------------------------------------------- /02-FundamentosAritmeticosEmJavaScript/4-5-ContagemDeCedulas/teste#4.js: -------------------------------------------------------------------------------- 1 | let notas = [100, 50, 20, 10, 5, 2, 1]; 2 | let notas1 = [0, 0, 0, 0, 0, 0, 0]; 3 | let quantia = parseInt(gets()); 4 | let resto = quantia; 5 | 6 | while (resto >= 1){ 7 | nota = notas.findIndex(value => value <= resto); 8 | notas1[nota] = Math.trunc(resto / notas[nota]); 9 | resto = resto % notas[nota]; 10 | } 11 | 12 | console.log(quantia); 13 | console.log(notas1[0] + " nota(s) de R$ 100,00"); 14 | console.log(notas1[1] + " nota(s) de R$ 50,00"); 15 | console.log(notas1[2] + " nota(s) de R$ 20,00"); 16 | console.log(notas1[3] + " nota(s) de R$ 10,00"); 17 | console.log(notas1[4] + " nota(s) de R$ 5,00"); 18 | console.log(notas1[5] + " nota(s) de R$ 2,00"); 19 | console.log(notas1[6] + " nota(s) de R$ 1,00"); -------------------------------------------------------------------------------- /02-FundamentosAritmeticosEmJavaScript/5-5-ConsumoMedioDoAutomovel/teste#5.js: -------------------------------------------------------------------------------- 1 | let X = parseFloat(gets()); 2 | let Y = parseFloat(gets()); 3 | let kmL = parseFloat(X / Y).toFixed(3); 4 | 5 | console.log(`${kmL} km/l`) -------------------------------------------------------------------------------- /03-OrdenacaoEFiltrosEmJavaScript/1-5-OrdenandoNumerosParesEImpares/Teste#1.js: -------------------------------------------------------------------------------- 1 | let num = 0; 2 | let index = 0; 3 | 4 | num = parseInt(gets()); 5 | 6 | let numeros = Array(num); 7 | 8 | while (index < num ) { 9 | numero = parseInt(gets()); 10 | if (numero >= 0 ) { 11 | numeros[index] = numero; 12 | index++; 13 | } 14 | }; 15 | 16 | pares = numeros.filter(value => value % 2 == 0); 17 | impares = numeros.filter(value => value % 2 != 0); 18 | pares.sort((a, b) => a-b); 19 | impares.sort((a, b) => b-a); 20 | 21 | pares.forEach(i => console.log(i)); 22 | impares.forEach(i => console.log(i)); -------------------------------------------------------------------------------- /03-OrdenacaoEFiltrosEmJavaScript/2-5-ComprasNoSupermercado/Teste#2.js: -------------------------------------------------------------------------------- 1 | let cases = parseInt(gets()); //Recebe quantidade de casos 2 | 3 | for (let j = 0; j < cases; j++) { 4 | let newProducts = (gets()).split(" ");//Recebe os produtos 5 | let list = new Set(newProducts); //Remove repetidos 1a parte 6 | let listOrdered = [...list].sort().toString().replace(/,/g, ' '); //2a parte, ordena. 7 | console.log(listOrdered); 8 | }; -------------------------------------------------------------------------------- /03-OrdenacaoEFiltrosEmJavaScript/3-5-UniformesDeFinalDeAno/Teste#3.js: -------------------------------------------------------------------------------- 1 | let cases = gets(); //Recebe quantidade de casos 2 | let students = []; 3 | 4 | for (let i = 0; i < cases; i++){ 5 | let name = gets(); 6 | let uniform = gets(); 7 | let colorSize = uniform.split(" "); 8 | let color = colorSize[0]; 9 | let size = colorSize[1]; 10 | 11 | students.push({ name, color, size }); 12 | } 13 | 14 | students.sort((a,b) => (a.color > b.color) ? 1 : 15 | (a.color === b.color) ? (a.size < b.size) ? 1 : 16 | (a.color === b.color) && (a.size === b.size) ? 17 | (a.name > b.name) ? 1 : -1 : -1 : -1); 18 | 19 | students.map(student => console.log(student.color, student.size, student.name)); -------------------------------------------------------------------------------- /03-OrdenacaoEFiltrosEmJavaScript/4-5-FilaDoBanco/Teste#4.js: -------------------------------------------------------------------------------- 1 | //Ordenando fila de banco por SMS do maior pelo menor 2 | let cases = parseInt(gets()); //Recebe quantidade de casos 3 | 4 | for (let i = 1; i <= cases; i++) { 5 | 6 | let stillInPosition = 0; //Conta os não alterados 7 | let numCustomers = parseInt(gets()); 8 | let arriving = (gets()).split(" ").map((arriving) => arriving); //Recebe os clientes 9 | //let arr1 = arriving.map((arriving) => arriving); 10 | let stack = arriving.map((arriving) => arriving).sort(sortNum); 11 | 12 | //Ordenando em ordem descrescente e númerica 13 | function sortNum(a, b){ 14 | return (b - a) //Função auxiliar para o array poder serja ordenado numericamente. 15 | } 16 | 17 | //Comparando valores para pegar os não alterados 18 | for (let j = 0; j < numCustomers; j++) { 19 | if ( arriving[j] === stack[j]) { 20 | stillInPosition++; 21 | }; 22 | }; 23 | //Saída dos não alterados 24 | console.log(stillInPosition); 25 | }; -------------------------------------------------------------------------------- /03-OrdenacaoEFiltrosEmJavaScript/5-5-GincanaNoAcampamento/Teste#5.js: -------------------------------------------------------------------------------- 1 | let stopped = 0; 2 | 3 | while (stopped !== 1 ) { 4 | 5 | let cases = parseInt(gets()); 6 | 7 | if (cases === 0) { 8 | stopped = 1; 9 | } else { 10 | 11 | let students = []; 12 | 13 | for (let i = 0; i < cases; i++){ 14 | let arriving = gets(); 15 | let nameNumber = arriving.split(" "); 16 | let name = nameNumber[0].normalize('NFD').replace(/[\u0300-\u036f]/g, ''); 17 | 18 | if (name.length > 30) name = name.substring(0,30); 19 | 20 | let number = parseInt(nameNumber[1]); 21 | students.push({ name, number }); 22 | } 23 | 24 | let circleNumber = students[0].number; 25 | students.reverse(); 26 | 27 | let target = 0; 28 | let rounds = 0; 29 | 30 | while (students.length !== 1) { 31 | 32 | let newCircle = []; 33 | 34 | if (circleNumber % 2 === 0) { 35 | 36 | for (let i = 0 ; i < circleNumber; i++) { 37 | 38 | if (rounds === 0) target = 0; 39 | if (target >= students.length) target = 0; 40 | newCircle[i] = students[target]; 41 | rounds++; 42 | 43 | if (i === circleNumber - 1 44 | && newCircle[newCircle.length - 1].number % 2 === 0) { 45 | target; 46 | } else if (i === circleNumber - 1 47 | && newCircle[newCircle.length - 1].number % 2 !== 0) { 48 | target--; 49 | } else { 50 | target++; 51 | } 52 | } 53 | } else { 54 | 55 | for (let i = 0 ; i < circleNumber; i++) { 56 | 57 | if (rounds === 0) target = students.length - 2; 58 | if (target < 0) target = students.length - 1; 59 | newCircle[i] = students[target]; 60 | rounds++; 61 | 62 | if (i === circleNumber - 1 63 | && newCircle[newCircle.length - 1].number % 2 === 0) { 64 | 65 | } else { 66 | target--; 67 | } 68 | } 69 | } 70 | 71 | circleNumber = newCircle[newCircle.length - 1].number; 72 | 73 | let index = students.indexOf(newCircle[newCircle.length - 1]); 74 | students.splice(index,1); 75 | 76 | } 77 | 78 | console.log(`Vencedor(a): ${students[students.length - 1].name}`); 79 | 80 | } 81 | 82 | } -------------------------------------------------------------------------------- /04-IntroduçãoABuscaE SubstituiçãoEmJavaScript/1-5-OrdenacaoDePalavrasPorTamanho/Teste1-5.js: -------------------------------------------------------------------------------- 1 | let cases = parseInt(gets()); // Receiving amount cases 2 | let arrivingSeparated = []; 3 | 4 | for (let i = 0; i < cases; i++) { 5 | arrivingSeparated[i] = gets() // Receiving cases 6 | .split(' ') // Separating words 7 | .sort((a, b) => (b.length > a.length) ? 1 : // Order by length 8 | (b.length === a.length) ? (a > b) -1 : -1) // Order by ASC 9 | .toString() 10 | .replace(/,/gi, " ") 11 | } 12 | for (sentence in arrivingSeparated) console.log(arrivingSeparated[sentence]); -------------------------------------------------------------------------------- /04-IntroduçãoABuscaE SubstituiçãoEmJavaScript/2-5-EncontreAMaiorSubstring/Teste2-5.js: -------------------------------------------------------------------------------- 1 | let stopped = 0; 2 | 3 | while (stopped !== 1) { 4 | 5 | let s1 = gets(), s2 = gets(), str1, str2, maxSubStr = 0, strings = []; 6 | 7 | if(s1 !== "" && s2 !== "") { 8 | 9 | if (s1.length < s2.length) { 10 | str1 = s2; str2 = s1; 11 | }else { 12 | str1 = s1; str2 = s2; 13 | } 14 | 15 | for (let i = 0; i < str2.length; i++) { 16 | for (let j = 0; j < str2.length; j++){ 17 | let nstr = str2.substring(j, str2.length - i); 18 | if (str1.match(nstr)) { 19 | strings.push(nstr); 20 | if (nstr.length > maxSubStr) maxSubStr = nstr.length; 21 | } 22 | } 23 | } 24 | 25 | console.log(`${maxSubStr}`); 26 | 27 | } else { 28 | stopped = 1; 29 | } 30 | } -------------------------------------------------------------------------------- /04-IntroduçãoABuscaE SubstituiçãoEmJavaScript/3-5-ValidadorDeSenhasComRequisitos/Teste3-5.js: -------------------------------------------------------------------------------- 1 | let stopped = 0; 2 | 3 | do { 4 | let password = gets(), // Receiving password 5 | upperCaseTest = password.toLocaleLowerCase(), 6 | lowerCaseTest = password.toLocaleUpperCase(), 7 | numberTest = password.match(/(\d)/i), 8 | specialCharTest = password.normalize('NFD').replace(/([\u0300-\u036f]|[^0-9a-zA-Z])/g, ''), 9 | lenghtTest = password.length >= 6 && password.length <= 32; 10 | 11 | // Validating 12 | if (password.length === 0) { 13 | 14 | } else { 15 | if (password !== upperCaseTest && 16 | password !== lowerCaseTest && 17 | password === specialCharTest && 18 | numberTest && lenghtTest) { 19 | console.log('Senha valida.'); 20 | } else { 21 | console.log('Senha invalida.'); 22 | } 23 | } 24 | if (password.length === 0 ) stopped = 1; 25 | 26 | } while (stopped !== 1) -------------------------------------------------------------------------------- /04-IntroduçãoABuscaE SubstituiçãoEmJavaScript/4-5-PedraPapelTesouraLagartoESpock/Teste4-5.js: -------------------------------------------------------------------------------- 1 | /*formato do dicionario de regras 2 | objeto['nome do item'] = lista_de_items_que_perdem pro 'nome_do_item' 3 | */ 4 | let dicionarioDeRegras = { 5 | tesoura: ['papel','lagarto'], 6 | papel: ['pedra','spock'], 7 | pedra: ['lagarto','tesoura'], 8 | lagarto: ['spock','papel'], 9 | spock: ['tesoura','pedra'] 10 | }; 11 | 12 | // formato: player1 vs player2 13 | let player1 = 'fernanda'; 14 | let player2 = 'marcia'; 15 | 16 | let resultado; 17 | 18 | let N = parseInt(gets()); 19 | for(var i=0;i") 21 | found = true 22 | } 23 | else{ 24 | entrada[j] = replaceAt(entrada[j], i, "") 25 | found= false; 26 | } 27 | } 28 | } 29 | } 30 | for( j = 0; j < entrada.length;j++){ 31 | for(i=0 ; i < entrada[j].length;i++ ){ 32 | 33 | if (entrada[j][i] === '*'){ 34 | if (!found) { 35 | entrada[j] = replaceAt(entrada[j], i, "") 36 | found = true 37 | } 38 | else{ 39 | entrada[j] = replaceAt(entrada[j], i, "") 40 | found= false; 41 | } 42 | } 43 | } 44 | } 45 | 46 | 47 | 48 | for( palavra in entrada){ 49 | console.log( entrada[palavra]) 50 | } -------------------------------------------------------------------------------- /05-SolucaoDeProblemasComJavaScript/1-7-ContagemRepetidaDeNumeros/Teste#1.js: -------------------------------------------------------------------------------- 1 | let N = parseInt(gets()); 2 | let nums = {}; 3 | let ns; 4 | for (let i = 0; i < N; i++) { 5 | ns = gets(); 6 | if(typeof nums[ns] === 'undefined') 7 | nums[ns] = {valor: parseInt(ns), cnt: 1}; 8 | else 9 | nums[ns].cnt++; 10 | } 11 | 12 | 13 | 14 | //console.log(nums); 15 | 16 | for(var [key, n] of Object.entries(nums)){ 17 | console.log(`${n.valor} aparece ${n.cnt} vez(es)`); 18 | } --------------------------------------------------------------------------------